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

Subversion Repositories thor

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

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

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2017-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      FT64.v
9
//      Features include:
10
//  - 16/32/48 bit instructions
11
//  - vector instruction set,
12
//  - SIMD instructions
13
//  - data width of 64 bits
14
//      - 32 general purpose registers
15
//  - 32 floating point registers
16
//      - 32 vector registers, length 63
17
//  - powerful branch prediction
18
//  - branch target buffer (BTB)
19
//  - return address predictor (RSB)
20
//  - bus interface unit
21
//  - instruction and data caches
22
//  - asynchronous logic loops for issue and branch miss
23
//    re-written for synchronous operation, not as elegant
24
//    but required for operation in an FPGA
25
//      - fine-grained simultaneous multi-threading (SMT)
26
//
27
// This source file is free software: you can redistribute it and/or modify 
28
// it under the terms of the GNU Lesser General Public License as published 
29
// by the Free Software Foundation, either version 3 of the License, or     
30
// (at your option) any later version.                                      
31
//                                                                          
32
// This source file is distributed in the hope that it will be useful,      
33
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
34
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
35
// GNU General Public License for more details.                             
36
//                                                                          
37
// You should have received a copy of the GNU General Public License        
38
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
39
//
40
// Approx. 100,000 LUTs. 160,000 LC's.
41 50 robfinch
// 38,000LUTs???
42 48 robfinch
// ============================================================================
43
//
44 49 robfinch
`include "FT64_config.vh"
45 48 robfinch
`include "FT64_defines.vh"
46
 
47
module FT64(hartid, rst, clk_i, clk4x, tm_clk_i, irq_i, vec_i, bte_o, cti_o, cyc_o, stb_o, ack_i, err_i, we_o, sel_o, adr_o, dat_o, dat_i,
48
    ol_o, pcr_o, pcr2_o, exv_i, rdv_i, wrv_i, icl_o, sr_o, cr_o, rbi_i, signal_i);
49
input [63:0] hartid;
50
input rst;
51
input clk_i;
52
input clk4x;
53
input tm_clk_i;
54 49 robfinch
input [3:0] irq_i;
55 48 robfinch
input [7:0] vec_i;
56
output reg [1:0] bte_o;
57
output reg [2:0] cti_o;
58
output reg cyc_o;
59
output reg stb_o;
60
input ack_i;
61
input err_i;
62
output reg we_o;
63
output reg [7:0] sel_o;
64 49 robfinch
output reg [`ABITS] adr_o;
65 48 robfinch
output reg [63:0] dat_o;
66
input [63:0] dat_i;
67
output reg [1:0] ol_o;
68
output [31:0] pcr_o;
69
output [63:0] pcr2_o;
70
input exv_i;
71
input rdv_i;
72
input wrv_i;
73
output reg icl_o;
74
output reg cr_o;
75
output reg sr_o;
76
input rbi_i;
77
input [31:0] signal_i;
78
 
79
parameter TM_CLKFREQ = 20000000;
80
parameter QENTRIES = `QENTRIES;
81
parameter RSTPC = 32'hFFFC0100;
82
parameter BRKPC = 32'hFFFC0000;
83
`ifdef SUPPORT_SMT
84
parameter PREGS = 256;   // number of physical registers - 1
85
parameter AREGS = 256;   // number of architectural registers
86
`else
87
parameter PREGS = 128;
88
parameter AREGS = 128;
89
`endif
90
parameter RBIT = 11;
91
parameter DEBUG = 1'b0;
92
parameter NMAP = QENTRIES;
93
parameter BRANCH_PRED = 1'b0;
94
parameter SUP_TXE = 1'b0;
95
parameter SUP_VECTOR = 1;
96
parameter DBW = 64;
97
parameter ABW = 32;
98
parameter AMSB = ABW-1;
99
parameter NTHREAD = 1;
100
reg [3:0] i;
101
integer n;
102
integer j;
103
genvar g;
104
parameter TRUE = 1'b1;
105
parameter FALSE = 1'b0;
106
// Memory access sizes
107
parameter byt = 3'd0;
108
parameter wyde = 3'd1;
109
parameter tetra = 3'd2;
110
parameter octa = 3'd3;
111
// IQ states
112
parameter IQS_IDLE = 2'd0;
113
parameter IQS_AGEN = 2'd1;
114
parameter IQS_LDDONE = 2'd2;
115
parameter IQS_S3 = 2'd3;
116
 
117
wire clk;
118 50 robfinch
//BUFG uclkb1
119
//(
120
//      .I(clk_i),
121
//      .O(clk)
122
//);
123
assign clk = clk_i;
124 48 robfinch
 
125
wire dc_ack;
126
wire acki = ack_i|dc_ack;
127
wire [RBIT:0] Ra0, Ra1;
128
wire [RBIT:0] Rb0, Rb1;
129
wire [RBIT:0] Rc0, Rc1;
130
wire [RBIT:0] Rt0, Rt1;
131
wire [63:0] rfoa0,rfob0,rfoc0,rfoc0a;
132
wire [63:0] rfoa1,rfob1,rfoc1,rfoc1a;
133
`ifdef SUPPORT_SMT
134
wire [7:0] Ra0s = {Ra0[7:0]};
135
wire [7:0] Ra1s = {Ra1[7:0]};
136
wire [7:0] Rb0s = {Rb0[7:0]};
137
wire [7:0] Rb1s = {Rb1[7:0]};
138
wire [7:0] Rc0s = {Rc0[7:0]};
139
wire [7:0] Rc1s = {Rc1[7:0]};
140
wire [7:0] Rt0s = {Rt0[7:0]};
141
wire [7:0] Rt1s = {Rt1[7:0]};
142
`else
143
wire [6:0] Ra0s = {Ra0[7],Ra0[5:0]};
144
wire [6:0] Ra1s = {Ra1[7],Ra1[5:0]};
145
wire [6:0] Rb0s = {Rb0[7],Rb0[5:0]};
146
wire [6:0] Rb1s = {Rb1[7],Rb1[5:0]};
147
wire [6:0] Rc0s = {Rc0[7],Rc0[5:0]};
148
wire [6:0] Rc1s = {Rc1[7],Rc1[5:0]};
149
wire [6:0] Rt0s = {Rt0[7],Rt0[5:0]};
150
wire [6:0] Rt1s = {Rt1[7],Rt1[5:0]};
151
/*
152
wire [5:0] Ra0s = {Ra0[5:0]};
153
wire [5:0] Ra1s = {Ra1[5:0]};
154
wire [5:0] Rb0s = {Rb0[5:0]};
155
wire [5:0] Rb1s = {Rb1[5:0]};
156
wire [5:0] Rc0s = {Rc0[5:0]};
157
wire [5:0] Rc1s = {Rc1[5:0]};
158
wire [5:0] Rt0s = {Rt0[5:0]};
159
wire [5:0] Rt1s = {Rt1[5:0]};
160
*/
161
`endif
162
 
163
reg [63:0] ds [0:NTHREAD];
164
reg [63:0] ss [0:NTHREAD];
165
reg [63:0] ptrmask [0:NTHREAD];
166
reg [63:0] ptrkey = "  OBJECT";
167
reg [63:0] wbrcd;
168
 
169
reg  [PREGS-1:0] rf_v;
170
reg  [4:0] rf_source[0:AREGS-1];
171
initial begin
172
for (n = 0; n < AREGS; n = n + 1)
173
        rf_source[n] = 5'd0;
174
end
175 49 robfinch
wire [`ABITS] pc0;
176
wire [`ABITS] pc1;
177
wire [`ABITS] pc2;
178 48 robfinch
 
179
reg excmiss;
180 49 robfinch
reg [`ABITS] excmisspc;
181 48 robfinch
reg excthrd;
182
reg exception_set;
183
reg rdvq;               // accumulated read violation
184
reg errq;               // accumulated err_i input status
185
reg exvq;
186
 
187
// Vector
188
reg [5:0] vqe0, vqe1;   // vector element being queued
189
reg [5:0] vqet0, vqet1;
190
reg [7:0] vl;           // vector length
191
reg [63:0] vm [0:7];    // vector mask registers
192
reg [1:0] m2;
193
 
194 49 robfinch
reg [31:0] wb_merges;
195 48 robfinch
// CSR's
196
reg [63:0] cr0;
197
wire snr = cr0[17];             // sequence number reset
198
wire dce = cr0[30];     // data cache enable
199
wire bpe = cr0[32];     // branch predictor enable
200
wire ctgtxe = cr0[33];
201 49 robfinch
reg [63:0] pmr;
202
wire id1_available = pmr[0];
203
wire id2_available = pmr[1];
204
wire id3_available = pmr[2];
205
wire alu0_available = pmr[8];
206
wire alu1_available = pmr[9];
207
wire fpu1_available = pmr[16];
208
wire fpu2_available = pmr[17];
209
wire mem1_available = pmr[24];
210
wire mem2_available = pmr[25];
211
wire mem3_available = pmr[26];
212
wire fcu_available = pmr[32];
213 48 robfinch
// Simply setting this flag to zero should strip out almost all the logic
214
// associated SMT.
215
`ifdef SUPPORT_SMT
216
wire thread_en = cr0[16];
217
`else
218
wire thread_en = 1'b0;
219
`endif
220
wire vechain = cr0[18];
221
reg [7:0] fcu_timeout;
222
reg [63:0] tick;
223
reg [63:0] wc_time;
224
reg [31:0] pcr;
225
reg [63:0] pcr2;
226
assign pcr_o = pcr;
227
assign pcr2_o = pcr2;
228
reg [63:0] aec;
229
reg [15:0] cause[0:15];
230
`ifdef SUPPORT_SMT
231 49 robfinch
reg [`ABITS] epc [0:NTHREAD];
232
reg [`ABITS] epc0 [0:NTHREAD];
233
reg [`ABITS] epc1 [0:NTHREAD];
234
reg [`ABITS] epc2 [0:NTHREAD];
235
reg [`ABITS] epc3 [0:NTHREAD];
236
reg [`ABITS] epc4 [0:NTHREAD];
237
reg [`ABITS] epc5 [0:NTHREAD];
238
reg [`ABITS] epc6 [0:NTHREAD];
239
reg [`ABITS] epc7 [0:NTHREAD];
240
reg [`ABITS] epc8 [0:NTHREAD];                   // exception pc and stack
241 48 robfinch
reg [63:0] mstatus [0:NTHREAD];           // machine status
242 49 robfinch
wire [3:0] im = mstatus[0][3:0];
243 48 robfinch
wire [1:0] ol [0:NTHREAD];
244
wire [1:0] dl [0:NTHREAD];
245
assign ol[0] = mstatus[0][5:3];   // operating level
246
assign dl[0] = mstatus[0][21:20];
247
wire [7:0] cpl [0:NTHREAD];
248
assign cpl[0] = mstatus[0][13:6]; // current privilege level
249
wire [5:0] rgs [0:NTHREAD];
250
assign rgs[0] = mstatus[0][19:14];
251
assign ol[1] = mstatus[1][5:3]; // operating level
252
assign cpl[1] = mstatus[1][13:6];       // current privilege level
253
assign rgs[1] = mstatus[1][19:14];
254
assign dl[1] = mstatus[1][21:20];
255
reg [15:0] ol_stack [0:NTHREAD];
256
reg [31:0] im_stack [0:NTHREAD];
257
reg [63:0] pl_stack [0:NTHREAD];
258
reg [63:0] rs_stack [0:NTHREAD];
259
reg [63:0] fr_stack [0:NTHREAD];
260
wire mprv = mstatus[0][55];
261
wire [5:0] fprgs = mstatus[0][25:20];
262
//assign ol_o = mprv ? ol_stack[0][2:0] : ol[0];
263
wire vca = mstatus[0][32];               // vector chaining active
264
`else
265 49 robfinch
reg [`ABITS] epc ;
266
reg [`ABITS] epc0 ;
267
reg [`ABITS] epc1 ;
268
reg [`ABITS] epc2 ;
269
reg [`ABITS] epc3 ;
270
reg [`ABITS] epc4 ;
271
reg [`ABITS] epc5 ;
272
reg [`ABITS] epc6 ;
273
reg [`ABITS] epc7 ;
274
reg [`ABITS] epc8 ;                     // exception pc and stack
275 48 robfinch
reg [63:0] mstatus ;             // machine status
276 49 robfinch
wire [3:0] im = mstatus[3:0];
277 48 robfinch
wire [1:0] ol ;
278
wire [1:0] dl;
279
assign ol = mstatus[5:3];       // operating level
280
assign dl = mstatus[21:20];
281
wire [7:0] cpl ;
282
assign cpl = mstatus[13:6];     // current privilege level
283
wire [5:0] rgs ;
284
assign rgs = mstatus[19:14];
285
reg [15:0] ol_stack ;
286
reg [31:0] im_stack ;
287
reg [63:0] pl_stack ;
288
reg [63:0] rs_stack ;
289
reg [63:0] fr_stack ;
290
wire mprv = mstatus[55];
291
wire [5:0] fprgs = mstatus[25:20];
292
//assign ol_o = mprv ? ol_stack[2:0] : ol;
293
wire vca = mstatus[32];         // vector chaining active
294
`endif
295
reg [63:0] tcb;
296 49 robfinch
reg [`ABITS] badaddr[0:15];
297
reg [`ABITS] tvec[0:7];
298 48 robfinch
reg [63:0] sema;
299
reg [63:0] vm_sema;
300
reg [63:0] cas;         // compare and swap
301
reg [63:0] ve_hold;
302
reg isCAS, isAMO, isInc, isSpt, isRMW;
303
reg [`QBITS] casid;
304 49 robfinch
reg [`ABITS] sbl, sbu;
305 48 robfinch
reg [4:0] regLR = 5'd29;
306
 
307 49 robfinch
reg [2:0] fp1_rm;
308
reg fp1_inexe;
309
reg fp1_dbzxe;
310
reg fp1_underxe;
311
reg fp1_overxe;
312
reg fp1_invopxe;
313
reg fp1_giopxe;
314
reg fp1_nsfp = 1'b0;
315
reg fp1_fractie;
316
reg fp1_raz;
317 48 robfinch
 
318 49 robfinch
reg fp1_neg;
319
reg fp1_pos;
320
reg fp1_zero;
321
reg fp1_inf;
322 48 robfinch
 
323 49 robfinch
reg fp1_inex;           // inexact exception
324
reg fp1_dbzx;           // divide by zero exception
325
reg fp1_underx;         // underflow exception
326
reg fp1_overx;          // overflow exception
327
reg fp1_giopx;          // global invalid operation exception
328
reg fp1_sx;                     // summary exception
329
reg fp1_swtx;        // software triggered exception
330
reg fp1_gx;
331
reg fp1_invopx;
332 48 robfinch
 
333 49 robfinch
reg fp1_infzerox;
334
reg fp1_zerozerox;
335
reg fp1_subinfx;
336
reg fp1_infdivx;
337
reg fp1_NaNCmpx;
338
reg fp1_cvtx;
339
reg fp1_sqrtx;
340
reg fp1_snanx;
341 48 robfinch
 
342 49 robfinch
reg [2:0] fp2_rm;
343
reg fp2_inexe;
344
reg fp2_dbzxe;
345
reg fp2_underxe;
346
reg fp2_overxe;
347
reg fp2_invopxe;
348
reg fp2_giopxe;
349
reg fp2_nsfp = 1'b0;
350
reg fp2_fractie;
351
reg fp2_raz;
352 48 robfinch
 
353 49 robfinch
reg fp2_neg;
354
reg fp2_pos;
355
reg fp2_zero;
356
reg fp2_inf;
357 48 robfinch
 
358 49 robfinch
reg fp2_inex;           // inexact exception
359
reg fp2_dbzx;           // divide by zero exception
360
reg fp2_underx;         // underflow exception
361
reg fp2_overx;          // overflow exception
362
reg fp2_giopx;          // global invalid operation exception
363
reg fp2_sx;                     // summary exception
364
reg fp2_swtx;        // software triggered exception
365
reg fp2_gx;
366
reg fp2_invopx;
367
 
368
reg fp2_infzerox;
369
reg fp2_zerozerox;
370
reg fp2_subinfx;
371
reg fp2_infdivx;
372
reg fp2_NaNCmpx;
373
reg fp2_cvtx;
374
reg fp2_sqrtx;
375
reg fp2_snanx;
376
 
377
wire [31:0] fp1_status = {
378
 
379
        fp1_rm,
380
        fp1_inexe,
381
        fp1_dbzxe,
382
        fp1_underxe,
383
        fp1_overxe,
384
        fp1_invopxe,
385
        fp1_nsfp,
386
 
387
        fp1_fractie,
388
        fp1_raz,
389 48 robfinch
        1'b0,
390 49 robfinch
        fp1_neg,
391
        fp1_pos,
392
        fp1_zero,
393
        fp1_inf,
394 48 robfinch
 
395 49 robfinch
        fp1_swtx,
396
        fp1_inex,
397
        fp1_dbzx,
398
        fp1_underx,
399
        fp1_overx,
400
        fp1_giopx,
401
        fp1_gx,
402
        fp1_sx,
403 48 robfinch
 
404 49 robfinch
        fp1_cvtx,
405
        fp1_sqrtx,
406
        fp1_NaNCmpx,
407
        fp1_infzerox,
408
        fp1_zerozerox,
409
        fp1_infdivx,
410
        fp1_subinfx,
411
        fp1_snanx
412 48 robfinch
        };
413
 
414 49 robfinch
wire [31:0] fp2_status = {
415 48 robfinch
 
416 49 robfinch
        fp2_rm,
417
        fp2_inexe,
418
        fp2_dbzxe,
419
        fp2_underxe,
420
        fp2_overxe,
421
        fp2_invopxe,
422
        fp2_nsfp,
423
 
424
        fp2_fractie,
425
        fp2_raz,
426
        1'b0,
427
        fp2_neg,
428
        fp2_pos,
429
        fp2_zero,
430
        fp2_inf,
431
 
432
        fp2_swtx,
433
        fp2_inex,
434
        fp2_dbzx,
435
        fp2_underx,
436
        fp2_overx,
437
        fp2_giopx,
438
        fp2_gx,
439
        fp2_sx,
440
 
441
        fp2_cvtx,
442
        fp2_sqrtx,
443
        fp2_NaNCmpx,
444
        fp2_infzerox,
445
        fp2_zerozerox,
446
        fp2_infdivx,
447
        fp2_subinfx,
448
        fp2_snanx
449
};
450
 
451
reg [63:0] fpu1_csr;
452
wire [5:0] fp1_rgs = fpu1_csr[37:32];
453
 
454 48 robfinch
//reg [25:0] m[0:8191];
455
reg  [3:0] panic;                // indexes the message structure
456
reg [128:0] message [0:15];       // indexed by panic
457
 
458
wire int_commit;
459
reg StatusHWI;
460 49 robfinch
reg [47:0] insn0, insn1, insn2;
461
wire [47:0] insn0a, insn1a, insn1b, insn2a, insn2b;
462 48 robfinch
reg tgtq;
463
// Only need enough bits in the seqnence number to cover the instructions in
464
// the queue plus an extra count for skipping on branch misses. In this case
465
// that would be four bits minimum (count 0 to 8). 
466
reg [31:0] seq_num;
467
reg [31:0] seq_num1;
468
wire [63:0] rdat0,rdat1,rdat2;
469
reg [63:0] xdati;
470
 
471
reg canq1, canq2;
472
reg queued1;
473
reg queued2;
474
reg queuedNop;
475
 
476
reg [47:0] codebuf[0:63];
477
reg [7:0] setpred;
478
 
479
// instruction queue (ROB)
480
reg [31:0]  iqentry_sn   [0:QENTRIES-1];  // instruction sequence number
481
reg [QENTRIES-1:0] iqentry_v;                    // entry valid?  -- this should be the first bit
482
reg [QENTRIES-1:0] iqentry_iv;           // instruction is valid
483
reg [4:0]  iqentry_is   [0:QENTRIES-1];   // source of instruction
484
reg [QENTRIES-1:0] iqentry_out;  // instruction has been issued to an ALU ... 
485
reg [QENTRIES-1:0] iqentry_done; // instruction result valid
486
reg [QENTRIES-1:0] iqentry_cmt;
487
reg [QENTRIES-1:0] iqentry_thrd;         // which thread the instruction is in
488
reg [QENTRIES-1:0] iqentry_pt;           // predict taken
489
reg [QENTRIES-1:0] iqentry_bt;   // branch-taken (used only for branches)
490
reg [QENTRIES-1:0] iqentry_agen; // address-generate ... signifies that address is ready (only for LW/SW)
491
reg  [1:0] iqentry_state [0:QENTRIES-1];
492
reg [QENTRIES-1:0] iqentry_alu = 8'h00;  // alu type instruction
493
reg [QENTRIES-1:0] iqentry_alu0;  // only valid on alu #0
494
reg [QENTRIES-1:0] iqentry_fpu;  // floating point instruction
495
reg [QENTRIES-1:0] iqentry_fc;   // flow control instruction
496
reg [QENTRIES-1:0] iqentry_canex = 8'h00;        // true if it's an instruction that can exception
497 50 robfinch
reg [QENTRIES-1:0] iqentry_oddball = 8'h00;      // writes to register file
498 49 robfinch
reg [QENTRIES-1:0] iqentry_load; // is a memory load instruction
499 50 robfinch
reg [QENTRIES-1:0] iqentry_loadv;        // is a volatile memory load instruction
500
reg [QENTRIES-1:0] iqentry_store;        // is a memory store instruction
501 49 robfinch
reg [QENTRIES-1:0] iqentry_preload;      // is a memory preload instruction
502
reg [QENTRIES-1:0] iqentry_ldcmp;
503
reg [QENTRIES-1:0] iqentry_mem;  // touches memory: 1 if LW/SW
504
reg [QENTRIES-1:0] iqentry_memndx;  // indexed memory operation 
505 50 robfinch
reg [2:0] iqentry_memsz [0:QENTRIES-1];   // size of memory op
506 49 robfinch
reg [QENTRIES-1:0] iqentry_rmw;  // memory RMW op
507
reg [QENTRIES-1:0] iqentry_memdb;
508
reg [QENTRIES-1:0] iqentry_memsb;
509
reg [QENTRIES-1:0] iqentry_rtop;
510 48 robfinch
reg [QENTRIES-1:0] iqentry_sei;
511
reg [QENTRIES-1:0] iqentry_aq;   // memory aquire
512
reg [QENTRIES-1:0] iqentry_rl;   // memory release
513 49 robfinch
reg [QENTRIES-1:0] iqentry_shft48;
514
reg [QENTRIES-1:0] iqentry_jmp;  // changes control flow: 1 if BEQ/JALR
515 48 robfinch
reg [QENTRIES-1:0] iqentry_br;  // Bcc (for predictor)
516 49 robfinch
reg [QENTRIES-1:0] iqentry_sync;  // sync instruction
517
reg [QENTRIES-1:0] iqentry_fsync;
518 48 robfinch
reg [QENTRIES-1:0] iqentry_rfw = 8'h00;  // writes to register file
519
reg  [7:0] iqentry_we   [0:QENTRIES-1];   // enable strobe
520
reg [63:0] iqentry_res   [0:QENTRIES-1];  // instruction result
521
reg [47:0] iqentry_instr[0:QENTRIES-1];   // instruction opcode
522
reg  [2:0] iqentry_insln[0:QENTRIES-1]; // instruction length
523
reg  [7:0] iqentry_exc   [0:QENTRIES-1];  // only for branches ... indicates a HALT instruction
524
reg [RBIT:0] iqentry_tgt [0:QENTRIES-1];  // Rt field or ZERO -- this is the instruction's target (if any)
525
reg  [7:0] iqentry_vl   [0:QENTRIES-1];
526
reg  [5:0] iqentry_ven  [0:QENTRIES-1];  // vector element number
527
reg [63:0] iqentry_a0    [0:QENTRIES-1];  // argument 0 (immediate)
528
reg [63:0] iqentry_a1    [0:QENTRIES-1];  // argument 1
529
reg        iqentry_a1_v [0:QENTRIES-1];  // arg1 valid
530
reg  [4:0] iqentry_a1_s  [0:QENTRIES-1];  // arg1 source (iq entry # with top bit representing ALU/DRAM bus)
531
reg [63:0] iqentry_a2    [0:QENTRIES-1];  // argument 2
532
reg        iqentry_a2_v [0:QENTRIES-1];  // arg2 valid
533
reg  [4:0] iqentry_a2_s  [0:QENTRIES-1];  // arg2 source (iq entry # with top bit representing ALU/DRAM bus)
534
reg [63:0] iqentry_a3    [0:QENTRIES-1];  // argument 3
535
reg        iqentry_a3_v [0:QENTRIES-1];  // arg3 valid
536
reg  [4:0] iqentry_a3_s  [0:QENTRIES-1];  // arg3 source (iq entry # with top bit representing ALU/DRAM bus)
537 49 robfinch
reg [`ABITS] iqentry_pc [0:QENTRIES-1];  // program counter for this instruction
538 48 robfinch
reg [RBIT:0] iqentry_Ra [0:QENTRIES-1];
539
reg [RBIT:0] iqentry_Rb [0:QENTRIES-1];
540
reg [RBIT:0] iqentry_Rc [0:QENTRIES-1];
541
// debugging
542
//reg  [4:0] iqentry_ra   [0:7];  // Ra
543
initial begin
544
for (n = 0; n < QENTRIES; n = n + 1)
545
        iqentry_a1_s[n] = 5'd0;
546
        iqentry_a2_s[n] = 5'd0;
547
        iqentry_a3_s[n] = 5'd0;
548
end
549
 
550
wire  [QENTRIES-1:0] iqentry_source = 8'h00;
551
reg   [QENTRIES-1:0] iqentry_imm;
552
wire  [QENTRIES-1:0] iqentry_memready;
553
wire  [QENTRIES-1:0] iqentry_memopsvalid;
554
 
555
reg  [QENTRIES-1:0] memissue = 8'h00;
556
reg [1:0] missued;
557
integer last_issue;
558
reg  [QENTRIES-1:0] iqentry_memissue;
559
wire [QENTRIES-1:0] iqentry_stomp;
560
reg [3:0] stompedOnRets;
561
reg  [QENTRIES-1:0] iqentry_alu0_issue;
562
reg  [QENTRIES-1:0] iqentry_alu1_issue;
563 49 robfinch
reg  [QENTRIES-1:0] iqentry_alu2_issue;
564 48 robfinch
reg  [QENTRIES-1:0] iqentry_id1issue;
565
reg  [QENTRIES-1:0] iqentry_id2issue;
566 49 robfinch
reg  [QENTRIES-1:0] iqentry_id3issue;
567 48 robfinch
reg [1:0] iqentry_mem_islot [0:QENTRIES-1];
568
reg [QENTRIES-1:0] iqentry_fcu_issue;
569 49 robfinch
reg [QENTRIES-1:0] iqentry_fpu1_issue;
570
reg [QENTRIES-1:0] iqentry_fpu2_issue;
571 48 robfinch
 
572
wire [PREGS-1:1] livetarget;
573
wire  [PREGS-1:1] iqentry_0_livetarget;
574
wire  [PREGS-1:1] iqentry_1_livetarget;
575
wire  [PREGS-1:1] iqentry_2_livetarget;
576
wire  [PREGS-1:1] iqentry_3_livetarget;
577
wire  [PREGS-1:1] iqentry_4_livetarget;
578
wire  [PREGS-1:1] iqentry_5_livetarget;
579
wire  [PREGS-1:1] iqentry_6_livetarget;
580
wire  [PREGS-1:1] iqentry_7_livetarget;
581
wire  [PREGS-1:1] iqentry_0_latestID;
582
wire  [PREGS-1:1] iqentry_1_latestID;
583
wire  [PREGS-1:1] iqentry_2_latestID;
584
wire  [PREGS-1:1] iqentry_3_latestID;
585
wire  [PREGS-1:1] iqentry_4_latestID;
586
wire  [PREGS-1:1] iqentry_5_latestID;
587
wire  [PREGS-1:1] iqentry_6_latestID;
588
wire  [PREGS-1:1] iqentry_7_latestID;
589
wire  [PREGS-1:1] iqentry_0_cumulative;
590
wire  [PREGS-1:1] iqentry_1_cumulative;
591
wire  [PREGS-1:1] iqentry_2_cumulative;
592
wire  [PREGS-1:1] iqentry_3_cumulative;
593
wire  [PREGS-1:1] iqentry_4_cumulative;
594
wire  [PREGS-1:1] iqentry_5_cumulative;
595
wire  [PREGS-1:1] iqentry_6_cumulative;
596
wire  [PREGS-1:1] iqentry_7_cumulative;
597
wire  [PREGS-1:1] iq0_out;
598
wire  [PREGS-1:1] iq1_out;
599
wire  [PREGS-1:1] iq2_out;
600
wire  [PREGS-1:1] iq3_out;
601
wire  [PREGS-1:1] iq4_out;
602
wire  [PREGS-1:1] iq5_out;
603
wire  [PREGS-1:1] iq6_out;
604
wire  [PREGS-1:1] iq7_out;
605
 
606
reg  [`QBITS] tail0;
607
reg  [`QBITS] tail1;
608
reg  [`QBITS] head0;
609
reg  [`QBITS] head1;
610
reg  [`QBITS] head2;    // used only to determine memory-access ordering
611
reg  [`QBITS] head3;    // used only to determine memory-access ordering
612
reg  [`QBITS] head4;    // used only to determine memory-access ordering
613
reg  [`QBITS] head5;    // used only to determine memory-access ordering
614
reg  [`QBITS] head6;    // used only to determine memory-access ordering
615
reg  [`QBITS] head7;    // used only to determine memory-access ordering
616
 
617
wire take_branch0;
618
wire take_branch1;
619
 
620
reg [3:0] nop_fetchbuf;
621
wire        fetchbuf;   // determines which pair to read from & write to
622 49 robfinch
wire [3:0] fb_panic;
623 48 robfinch
 
624
wire [47:0] fetchbuf0_instr;
625
wire  [2:0] fetchbuf0_insln;
626 49 robfinch
wire [`ABITS] fetchbuf0_pc;
627 48 robfinch
wire        fetchbuf0_v;
628
wire            fetchbuf0_thrd;
629
wire        fetchbuf0_mem;
630
wire            fetchbuf0_memld;
631
wire        fetchbuf0_jmp;
632
wire        fetchbuf0_rfw;
633
wire [47:0] fetchbuf1_instr;
634
wire  [2:0] fetchbuf1_insln;
635 49 robfinch
wire [`ABITS] fetchbuf1_pc;
636 48 robfinch
wire        fetchbuf1_v;
637
wire            fetchbuf1_thrd;
638
wire        fetchbuf1_mem;
639
wire            fetchbuf1_memld;
640
wire        fetchbuf1_jmp;
641
wire        fetchbuf1_rfw;
642
 
643
wire [47:0] fetchbufA_instr;
644 49 robfinch
wire [`ABITS] fetchbufA_pc;
645 48 robfinch
wire        fetchbufA_v;
646
wire [47:0] fetchbufB_instr;
647 49 robfinch
wire [`ABITS] fetchbufB_pc;
648 48 robfinch
wire        fetchbufB_v;
649
wire [47:0] fetchbufC_instr;
650 49 robfinch
wire [`ABITS] fetchbufC_pc;
651 48 robfinch
wire        fetchbufC_v;
652
wire [47:0] fetchbufD_instr;
653 49 robfinch
wire [`ABITS] fetchbufD_pc;
654 48 robfinch
wire        fetchbufD_v;
655
 
656
//reg        did_branchback0;
657
//reg        did_branchback1;
658
 
659
reg         id1_v;
660
reg   [4:0] id1_id;
661
reg  [47:0] id1_instr;
662
reg   [5:0] id1_ven;
663
reg   [7:0] id1_vl;
664
reg         id1_thrd;
665
reg         id1_pt;
666
reg   [4:0] id1_Rt;
667
wire [127:0] id1_bus;
668
 
669
reg         id2_v;
670
reg   [4:0] id2_id;
671
reg  [47:0] id2_instr;
672
reg   [5:0] id2_ven;
673
reg   [7:0] id2_vl;
674
reg         id2_thrd;
675
reg         id2_pt;
676
reg   [4:0] id2_Rt;
677
wire [127:0] id2_bus;
678
 
679 49 robfinch
reg         id3_v;
680
reg   [4:0] id3_id;
681
reg  [47:0] id3_instr;
682
reg   [5:0] id3_ven;
683
reg   [7:0] id3_vl;
684
reg         id3_thrd;
685
reg         id3_pt;
686
reg   [4:0] id3_Rt;
687
wire [127:0] id3_bus;
688
 
689 48 robfinch
reg        alu0_ld;
690
reg        alu0_dataready;
691
wire       alu0_done;
692
wire       alu0_idle;
693
reg  [3:0] alu0_sourceid;
694
reg [47:0] alu0_instr;
695
reg        alu0_bt;
696
reg        alu0_mem;
697
reg        alu0_shft48;
698
reg [63:0] alu0_argA;
699
reg [63:0] alu0_argB;
700
reg [63:0] alu0_argC;
701
reg [63:0] alu0_argI;    // only used by BEQ
702
reg [RBIT:0] alu0_tgt;
703
reg [5:0]  alu0_ven;
704
reg        alu0_thrd;
705 49 robfinch
reg [`ABITS] alu0_pc;
706 48 robfinch
wire [63:0] alu0_bus;
707
wire [63:0] alu0b_bus;
708
wire  [3:0] alu0_id;
709 49 robfinch
wire  [`XBITS] alu0_exc;
710 48 robfinch
wire        alu0_v;
711
wire        alu0_branchmiss;
712 49 robfinch
wire [`ABITS] alu0_misspc;
713 48 robfinch
 
714
reg        alu1_ld;
715
reg        alu1_dataready;
716
wire       alu1_done;
717
wire       alu1_idle;
718
reg  [3:0] alu1_sourceid;
719
reg [47:0] alu1_instr;
720
reg        alu1_bt;
721
reg        alu1_mem;
722
reg        alu1_shft48;
723
reg [63:0] alu1_argA;
724
reg [63:0] alu1_argB;
725
reg [63:0] alu1_argC;
726
reg [63:0] alu1_argI;    // only used by BEQ
727
reg [RBIT:0] alu1_tgt;
728
reg [5:0]  alu1_ven;
729 49 robfinch
reg [`ABITS] alu1_pc;
730 48 robfinch
reg        alu1_thrd;
731
wire [63:0] alu1_bus;
732
wire [63:0] alu1b_bus;
733
wire  [3:0] alu1_id;
734 49 robfinch
wire  [`XBITS] alu1_exc;
735 48 robfinch
wire        alu1_v;
736
wire        alu1_branchmiss;
737 49 robfinch
wire [`ABITS] alu1_misspc;
738 48 robfinch
 
739 49 robfinch
reg        fpu1_ld;
740
reg        fpu1_dataready = 1'b1;
741
wire       fpu1_done = 1'b1;
742
wire       fpu1_idle;
743
reg  [3:0] fpu1_sourceid;
744
reg [47:0] fpu1_instr;
745
reg [63:0] fpu1_argA;
746
reg [63:0] fpu1_argB;
747
reg [63:0] fpu1_argC;
748
reg [63:0] fpu1_argI;    // only used by BEQ
749
reg [RBIT:0] fpu1_tgt;
750
reg [`ABITS] fpu1_pc;
751
wire [63:0] fpu1_bus;
752
wire  [3:0] fpu1_id;
753
wire  [`XBITS] fpu1_exc = 9'h000;
754
wire        fpu1_v;
755
wire [31:0] fpu1_status;
756 48 robfinch
 
757 49 robfinch
reg        fpu2_ld;
758
reg        fpu2_dataready = 1'b1;
759
wire       fpu2_done = 1'b1;
760
wire       fpu2_idle;
761
reg  [3:0] fpu2_sourceid;
762
reg [47:0] fpu2_instr;
763
reg [63:0] fpu2_argA;
764
reg [63:0] fpu2_argB;
765
reg [63:0] fpu2_argC;
766
reg [63:0] fpu2_argI;    // only used by BEQ
767
reg [RBIT:0] fpu2_tgt;
768
reg [`ABITS] fpu2_pc;
769
wire [63:0] fpu2_bus;
770
wire  [3:0] fpu2_id;
771
wire  [`XBITS] fpu2_exc = 9'h000;
772
wire        fpu2_v;
773
wire [31:0] fpu2_status;
774
 
775 48 robfinch
reg [63:0] waitctr;
776
reg        fcu_ld;
777
reg        fcu_dataready;
778
reg        fcu_done;
779
reg         fcu_idle = 1'b1;
780
reg  [3:0] fcu_sourceid;
781
reg [47:0] fcu_instr;
782
reg  [2:0] fcu_insln;
783
reg        fcu_call;
784
reg        fcu_bt;
785
reg [63:0] fcu_argA;
786
reg [63:0] fcu_argB;
787
reg [63:0] fcu_argC;
788
reg [63:0] fcu_argI;     // only used by BEQ
789
reg [63:0] fcu_argT;
790
reg [63:0] fcu_argT2;
791 49 robfinch
reg [`ABITS] fcu_retadr;
792 48 robfinch
reg        fcu_retadr_v;
793 49 robfinch
reg [`ABITS] fcu_pc;
794
reg [`ABITS] fcu_nextpc;
795
reg [`ABITS] fcu_brdisp;
796 48 robfinch
wire [63:0] fcu_bus;
797
wire  [3:0] fcu_id;
798 49 robfinch
reg   [`XBITS] fcu_exc;
799 48 robfinch
wire        fcu_v;
800
reg        fcu_thrd;
801
reg        fcu_branchmiss;
802
reg  fcu_clearbm;
803 49 robfinch
reg [`ABITS] fcu_misspc;
804 48 robfinch
 
805
reg [63:0] rmw_argA;
806
reg [63:0] rmw_argB;
807
reg [63:0] rmw_argC;
808
wire [63:0] rmw_res;
809
reg [31:0] rmw_instr;
810
 
811 49 robfinch
// write buffer
812
reg [63:0] wb_data [0:`WB_DEPTH-1];
813
reg [`ABITS] wb_addr [0:`WB_DEPTH-1];
814
reg [1:0] wb_ol [0:`WB_DEPTH-1];
815
reg [`WB_DEPTH-1:0] wb_v;
816
reg [`WB_DEPTH-1:0] wb_rmw;
817
reg [QENTRIES-1:0] wb_id [0:`WB_DEPTH-1];
818
reg [QENTRIES-1:0] wbo_id;
819
reg [7:0] wb_sel [0:`WB_DEPTH-1];
820
reg wb_en;
821
 
822 48 robfinch
reg branchmiss = 1'b0;
823
reg branchmiss_thrd = 1'b0;
824 49 robfinch
reg [`ABITS] misspc;
825 48 robfinch
reg  [`QBITS] missid;
826
 
827
wire take_branch;
828
wire take_branchA;
829
wire take_branchB;
830
wire take_branchC;
831
wire take_branchD;
832
 
833
wire        dram_avail;
834
reg      [2:0] dram0;    // state of the DRAM request (latency = 4; can have three in pipeline)
835
reg      [2:0] dram1;    // state of the DRAM request (latency = 4; can have three in pipeline)
836
reg      [2:0] dram2;    // state of the DRAM request (latency = 4; can have three in pipeline)
837
reg [63:0] dram0_data;
838 49 robfinch
reg [`ABITS] dram0_addr;
839 48 robfinch
reg [31:0] dram0_seg;
840
reg [47:0] dram0_instr;
841
reg        dram0_rmw;
842
reg                dram0_preload;
843
reg [RBIT:0] dram0_tgt;
844
reg  [3:0] dram0_id;
845 49 robfinch
reg  [`XBITS] dram0_exc;
846 48 robfinch
reg        dram0_unc;
847
reg [2:0]  dram0_memsize;
848
reg        dram0_load;  // is a load operation
849 50 robfinch
reg        dram0_store;
850 48 robfinch
reg  [1:0] dram0_ol;
851
reg [63:0] dram1_data;
852 49 robfinch
reg [`ABITS] dram1_addr;
853 48 robfinch
reg [31:0] dram1_seg;
854
reg [47:0] dram1_instr;
855
reg        dram1_rmw;
856
reg                dram1_preload;
857
reg [RBIT:0] dram1_tgt;
858
reg  [3:0] dram1_id;
859 49 robfinch
reg  [`XBITS] dram1_exc;
860 48 robfinch
reg        dram1_unc;
861
reg [2:0]  dram1_memsize;
862
reg        dram1_load;
863 50 robfinch
reg        dram1_store;
864 48 robfinch
reg  [1:0] dram1_ol;
865
reg [63:0] dram2_data;
866 49 robfinch
reg [`ABITS] dram2_addr;
867 48 robfinch
reg [31:0] dram2_seg;
868
reg [47:0] dram2_instr;
869
reg        dram2_rmw;
870
reg                dram2_preload;
871
reg [RBIT:0] dram2_tgt;
872
reg  [3:0] dram2_id;
873 49 robfinch
reg  [`XBITS] dram2_exc;
874 48 robfinch
reg        dram2_unc;
875
reg [2:0]  dram2_memsize;
876
reg        dram2_load;
877 50 robfinch
reg        dram2_store;
878 48 robfinch
reg  [1:0] dram2_ol;
879
 
880
reg        dramA_v;
881
reg  [3:0] dramA_id;
882
reg [63:0] dramA_bus;
883 49 robfinch
reg  [`XBITS] dramA_exc;
884 48 robfinch
reg        dramB_v;
885
reg  [3:0] dramB_id;
886
reg [63:0] dramB_bus;
887 49 robfinch
reg  [`XBITS] dramB_exc;
888 48 robfinch
reg        dramC_v;
889
reg  [3:0] dramC_id;
890
reg [63:0] dramC_bus;
891 49 robfinch
reg  [`XBITS] dramC_exc;
892 48 robfinch
 
893
wire        outstanding_stores;
894
reg [63:0] I;    // instruction count
895
 
896
reg        commit0_v;
897
reg  [4:0] commit0_id;
898
reg [RBIT:0] commit0_tgt;
899
reg  [7:0] commit0_we = 8'h00;
900
reg [63:0] commit0_bus;
901
reg        commit1_v;
902
reg  [4:0] commit1_id;
903
reg [RBIT:0] commit1_tgt;
904
reg  [7:0] commit1_we = 8'h00;
905
reg [63:0] commit1_bus;
906
 
907
reg [4:0] bstate;
908
parameter BIDLE = 5'd0;
909
parameter B1 = 5'd1;
910
parameter B2 = 5'd2;
911
parameter B3 = 5'd3;
912
parameter B4 = 5'd4;
913
parameter B5 = 5'd5;
914
parameter B6 = 5'd6;
915
parameter B7 = 5'd7;
916
parameter B8 = 5'd8;
917
parameter B9 = 5'd9;
918
parameter B10 = 5'd10;
919
parameter B11 = 5'd11;
920
parameter B12 = 5'd12;
921
parameter B13 = 5'd13;
922
parameter B14 = 5'd14;
923
parameter B15 = 5'd15;
924
parameter B16 = 5'd16;
925
parameter B17 = 5'd17;
926
parameter B18 = 5'd18;
927
parameter B19 = 5'd19;
928
parameter B2a = 5'd20;
929
parameter B2b = 5'd21;
930
parameter B2c = 5'd22;
931
parameter B2d = 5'd23;
932
parameter B20 = 5'd24;
933
parameter B21 = 5'd25;
934
reg [1:0] bwhich;
935
reg [3:0] icstate,picstate;
936
parameter IDLE = 4'd0;
937
parameter IC1 = 4'd1;
938
parameter IC2 = 4'd2;
939
parameter IC3 = 4'd3;
940
parameter IC4 = 4'd4;
941
parameter IC5 = 4'd5;
942
parameter IC6 = 4'd6;
943
parameter IC7 = 4'd7;
944
parameter IC8 = 4'd8;
945
parameter IC9 = 4'd9;
946
parameter IC10 = 4'd10;
947
parameter IC3a = 4'd11;
948
reg invic, invdc;
949 49 robfinch
reg [1:0] icwhich;
950
reg icnxt,L2_nxt;
951
wire ihit0,ihit1,ihit2,ihitL2;
952
wire ihit = ihit0&ihit1&ihit2;
953 48 robfinch
reg phit;
954
wire threadx;
955
always @*
956
        phit <= ihit&&icstate==IDLE;
957
reg [2:0] iccnt;
958 49 robfinch
reg L1_wr0,L1_wr1,L1_wr2;
959 48 robfinch
reg L1_invline;
960 49 robfinch
reg [8:0] L1_en;
961 48 robfinch
reg [37:0] L1_adr, L2_adr;
962 49 robfinch
reg [287:0] L2_rdat;
963
wire [287:0] L2_dato;
964 48 robfinch
reg L2_xsel;
965
 
966
FT64_regfile2w6r_oc #(.RBIT(RBIT)) urf1
967
(
968
  .clk(clk),
969
  .clk4x(clk4x),
970
  .wr0(commit0_v),
971
  .wr1(commit1_v),
972
  .we0(commit0_we),
973
  .we1(commit1_we),
974
  .wa0(commit0_tgt),
975
  .wa1(commit1_tgt),
976
  .i0(commit0_bus),
977
  .i1(commit1_bus),
978
        .rclk(~clk),
979
        .ra0(Ra0),
980
        .ra1(Rb0),
981
        .ra2(Rc0),
982
        .ra3(Ra1),
983
        .ra4(Rb1),
984
        .ra5(Rc1),
985
        .o0(rfoa0),
986
        .o1(rfob0),
987
        .o2(rfoc0a),
988
        .o3(rfoa1),
989
        .o4(rfob1),
990
        .o5(rfoc1a)
991
);
992
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
993
assign rfoc1 = Rc1[11:6]==6'h3F ? vm[Rc1[2:0]] : rfoc1a;
994
 
995
function [2:0] fnInsLength;
996
input [47:0] ins;
997
case(ins[7:6])
998
2'b00:  fnInsLength = 3'd4;
999
2'b01:  fnInsLength = 3'd6;
1000
2'b10:  fnInsLength = 3'd2;
1001
2'b11:  fnInsLength = 3'd2;
1002
endcase
1003
endfunction
1004
 
1005 49 robfinch
wire [`ABITS] pc0plus6 = pc0 + 32'd6;
1006
wire [`ABITS] pc0plus12 = pc0 + 32'd12;
1007 48 robfinch
 
1008
`ifdef SUPPORT_SMT
1009 49 robfinch
generate begin : gInsnVar
1010
        if (`WAYS > 1) begin
1011
                assign insn1a = insn1b;
1012
        end
1013
        if (`WAYS > 2) begin
1014
                assign insn2a = insn2b;
1015
        end
1016
end
1017
endgenerate
1018 48 robfinch
`else
1019 49 robfinch
generate begin : gInsnVar
1020
        if (`WAYS > 1) begin
1021
                assign insn1a = {insn1b,insn0a} >> {fnInsLength(insn0a),3'b0};
1022
        end
1023
        if (`WAYS > 2) begin
1024
                assign insn2a = {insn2b,insn1b,insn0a} >> {fnInsLength(insn0a) + fnInsLength(insn1a),3'b0};
1025
        end
1026
end
1027
endgenerate
1028 48 robfinch
`endif
1029
 
1030
FT64_L1_icache uic0
1031
(
1032
    .rst(rst),
1033
    .clk(clk),
1034
    .nxt(icnxt),
1035
    .wr(L1_wr0),
1036
    .en(L1_en),
1037
    .adr(icstate==IDLE||icstate==IC8 ? {pcr[5:0],pc0} : L1_adr),
1038
    .wadr(L1_adr),
1039
    .i(L2_rdat),
1040
    .o(insn0a),
1041
    .hit(ihit0),
1042
    .invall(invic),
1043
    .invline(L1_invline)
1044
);
1045 49 robfinch
generate begin : gICacheInst
1046
if (`WAYS > 1) begin
1047 48 robfinch
FT64_L1_icache uic1
1048
(
1049
    .rst(rst),
1050
    .clk(clk),
1051
    .nxt(icnxt),
1052
    .wr(L1_wr1),
1053
    .en(L1_en),
1054
`ifdef SUPPORT_SMT
1055
    .adr(icstate==IDLE||icstate==IC8 ? {pcr[5:0],pc1} : L1_adr),
1056
`else
1057
    .adr(icstate==IDLE||icstate==IC8 ? {pcr[5:0],pc0plus6} : L1_adr),
1058
`endif
1059
    .wadr(L1_adr),
1060
    .i(L2_rdat),
1061
    .o(insn1b),
1062
    .hit(ihit1),
1063
    .invall(invic),
1064
    .invline(L1_invline)
1065
);
1066 49 robfinch
end
1067
else begin
1068
assign ihit1 = 1'b1;
1069
end
1070
if (`WAYS > 2) begin
1071
FT64_L1_icache uic2
1072
(
1073
    .rst(rst),
1074
    .clk(clk),
1075
    .nxt(icnxt),
1076
    .wr(L1_wr2),
1077
    .en(L1_en),
1078
`ifdef SUPPORT_SMT
1079
    .adr(icstate==IDLE||icstate==IC8 ? {pcr[5:0],pc2} : L1_adr),
1080
`else
1081
    .adr(icstate==IDLE||icstate==IC8 ? {pcr[5:0],pc0plus12} : L1_adr),
1082
`endif
1083
    .wadr(L1_adr),
1084
    .i(L2_rdat),
1085
    .o(insn2b),
1086
    .hit(ihit2),
1087
    .invall(invic),
1088
    .invline(L1_invline)
1089
);
1090
end
1091
else
1092
assign ihit2 = 1'b1;
1093
end
1094
endgenerate
1095
 
1096 48 robfinch
FT64_L2_icache uic2
1097
(
1098
    .rst(rst),
1099
    .clk(clk),
1100
    .nxt(L2_nxt),
1101
    .wr(bstate==B7 && ack_i),
1102
    .xsel(L2_xsel),
1103
    .adr(L2_adr),
1104
    .cnt(iccnt),
1105
    .exv_i(exvq),
1106
    .i(dat_i),
1107
    .err_i(errq),
1108
    .o(L2_dato),
1109 49 robfinch
    .hit(ihitL2),
1110 48 robfinch
    .invall(invic),
1111
    .invline()
1112
);
1113
 
1114
wire predict_taken;
1115
wire predict_taken0;
1116
wire predict_taken1;
1117
wire predict_takenA;
1118
wire predict_takenB;
1119
wire predict_takenC;
1120
wire predict_takenD;
1121
wire predict_takenA1;
1122
wire predict_takenB1;
1123
wire predict_takenC1;
1124
wire predict_takenD1;
1125
 
1126 49 robfinch
wire [`ABITS] btgtA, btgtB, btgtC, btgtD;
1127 48 robfinch
wire btbwr0 = iqentry_v[head0] && iqentry_done[head0] &&
1128
        (
1129
        iqentry_instr[head0][`INSTRUCTION_OP]==`JAL ||
1130
        iqentry_instr[head0][`INSTRUCTION_OP]==`BRK ||
1131
        IsRTI(iqentry_instr[head0]));
1132
wire btbwr1 = iqentry_v[head1] && iqentry_done[head1] &&
1133
        (
1134
        iqentry_instr[head1][`INSTRUCTION_OP]==`JAL ||
1135
        iqentry_instr[head1][`INSTRUCTION_OP]==`BRK ||
1136
        IsRTI(iqentry_instr[head1]));
1137
 
1138 50 robfinch
wire fcu_clk;
1139 49 robfinch
`ifdef FCU_ENH
1140 50 robfinch
//BUFGCE ufcuclk
1141
//(
1142
//      .I(clk_i),
1143
//      .CE(fcu_available),
1144
//      .O(fcu_clk)
1145
//);
1146 49 robfinch
`endif
1147 50 robfinch
assign fcu_clk = clk_i;
1148 49 robfinch
 
1149
`ifdef FCU_ENH
1150 48 robfinch
FT64_BTB ubtb1
1151
(
1152 49 robfinch
  .rst(rst),
1153
  .wclk(fcu_clk),
1154
  .wr(btbwr0 | btbwr1),
1155
  .wadr(btbwr0 ? iqentry_pc[head0] : iqentry_pc[head1]),
1156
  .wdat(btbwr0 ? iqentry_a0[head0] : iqentry_a0[head1]),
1157
  .valid(btbwr0 ? iqentry_bt[head0] & iqentry_v[head0] : iqentry_bt[head1] & iqentry_v[head1]),
1158
  .rclk(~clk),
1159
  .pcA(fetchbufA_pc),
1160
  .btgtA(btgtA),
1161
  .pcB(fetchbufB_pc),
1162
  .btgtB(btgtB),
1163
  .pcC(fetchbufC_pc),
1164
  .btgtC(btgtC),
1165
  .pcD(fetchbufD_pc),
1166
  .btgtD(btgtD),
1167
  .npcA(BRKPC),
1168
  .npcB(BRKPC),
1169
  .npcC(BRKPC),
1170
  .npcD(BRKPC)
1171 48 robfinch
);
1172 49 robfinch
`else
1173
// Branch tergets are picked up by fetchbuf logic and need to be present.
1174
// Without a target predictor they are just set to the reset address.
1175
// This virtually guarentees a miss.
1176
assign btgtA = RSTPC;
1177
assign btgtB = RSTPC;
1178
assign btgtC = RSTPC;
1179
assign btgtD = RSTPC;
1180
`endif
1181 48 robfinch
 
1182 49 robfinch
`ifdef FCU_ENH
1183 48 robfinch
FT64_BranchPredictor ubp1
1184
(
1185 49 robfinch
  .rst(rst),
1186
  .clk(fcu_clk),
1187
  .en(bpe),
1188
  .xisBranch0(iqentry_br[head0] & commit0_v),
1189
  .xisBranch1(iqentry_br[head1] & commit1_v),
1190
  .pcA(fetchbufA_pc),
1191
  .pcB(fetchbufB_pc),
1192
  .pcC(fetchbufC_pc),
1193
  .pcD(fetchbufD_pc),
1194
  .xpc0(iqentry_pc[head0]),
1195
  .xpc1(iqentry_pc[head1]),
1196
  .takb0(commit0_v & iqentry_res[head0][0]),
1197
  .takb1(commit1_v & iqentry_res[head1][0]),
1198
  .predict_takenA(predict_takenA),
1199
  .predict_takenB(predict_takenB),
1200
  .predict_takenC(predict_takenC),
1201
  .predict_takenD(predict_takenD)
1202 48 robfinch
);
1203 49 robfinch
`else
1204
// Predict based on sign of displacement
1205
assign predict_takenA = fetchbufA_instr[31];
1206
assign predict_takenB = fetchbufB_instr[31];
1207
assign predict_takenC = fetchbufC_instr[31];
1208
assign predict_takenD = fetchbufD_instr[31];
1209
`endif
1210 48 robfinch
 
1211
//-----------------------------------------------------------------------------
1212
// Debug
1213
//-----------------------------------------------------------------------------
1214
`ifdef SUPPORT_DBG
1215
 
1216
wire [DBW-1:0] dbg_stat1x;
1217
reg [DBW-1:0] dbg_stat;
1218
reg [DBW-1:0] dbg_ctrl;
1219
reg [ABW-1:0] dbg_adr0;
1220
reg [ABW-1:0] dbg_adr1;
1221
reg [ABW-1:0] dbg_adr2;
1222
reg [ABW-1:0] dbg_adr3;
1223
reg dbg_imatchA0,dbg_imatchA1,dbg_imatchA2,dbg_imatchA3,dbg_imatchA;
1224
reg dbg_imatchB0,dbg_imatchB1,dbg_imatchB2,dbg_imatchB3,dbg_imatchB;
1225
 
1226
wire dbg_lmatch00 =
1227
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1228
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1229
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1230
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1231
                                 dbg_ctrl[19:18]==2'b11)
1232
                                 ;
1233
wire dbg_lmatch01 =
1234
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1235
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1236
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1237
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1238
                  dbg_ctrl[19:18]==2'b11)
1239
                  ;
1240
wire dbg_lmatch02 =
1241
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1242
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1243
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1244
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1245
                dbg_ctrl[19:18]==2'b11)
1246
                ;
1247
wire dbg_lmatch10 =
1248
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1249
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1250
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1251
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1252
                  dbg_ctrl[23:22]==2'b11)
1253
                  ;
1254
wire dbg_lmatch11 =
1255
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1256
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1257
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1258
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1259
                dbg_ctrl[23:22]==2'b11)
1260
                ;
1261
wire dbg_lmatch12 =
1262
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1263
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1264
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1265
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1266
                dbg_ctrl[23:22]==2'b11)
1267
                ;
1268
wire dbg_lmatch20 =
1269
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1270
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1271
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1272
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1273
                    dbg_ctrl[27:26]==2'b11)
1274
                    ;
1275
wire dbg_lmatch21 =
1276
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1277
                   ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1278
                    (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1279
                    (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1280
                    dbg_ctrl[27:26]==2'b11)
1281
                    ;
1282
wire dbg_lmatch22 =
1283
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1284
                   ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1285
                    (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1286
                    (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1287
                    dbg_ctrl[27:26]==2'b11)
1288
                    ;
1289
wire dbg_lmatch30 =
1290
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1291
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1292
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1293
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1294
                      dbg_ctrl[31:30]==2'b11)
1295
                      ;
1296
wire dbg_lmatch31 =
1297
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1298
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1299
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1300
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1301
                    dbg_ctrl[31:30]==2'b11)
1302
                    ;
1303
wire dbg_lmatch32 =
1304
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1305
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1306
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1307
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1308
                    dbg_ctrl[31:30]==2'b11)
1309
                    ;
1310
wire dbg_lmatch0 = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30;
1311
wire dbg_lmatch1 = dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31;
1312
wire dbg_lmatch2 = dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32;
1313
wire dbg_lmatch = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30|
1314
                  dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31|
1315
                  dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32
1316
                    ;
1317
 
1318
wire dbg_smatch00 =
1319
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1320
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1321
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1322
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1323
                                 dbg_ctrl[19:18]==2'b11)
1324
                                 ;
1325
wire dbg_smatch01 =
1326
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1327
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1328
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1329
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1330
                  dbg_ctrl[19:18]==2'b11)
1331
                  ;
1332
wire dbg_smatch02 =
1333
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1334
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1335
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1336
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1337
                dbg_ctrl[19:18]==2'b11)
1338
                ;
1339
wire dbg_smatch10 =
1340
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1341
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1342
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1343
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1344
                  dbg_ctrl[23:22]==2'b11)
1345
                  ;
1346
wire dbg_smatch11 =
1347
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1348
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1349
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1350
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1351
                dbg_ctrl[23:22]==2'b11)
1352
                ;
1353
wire dbg_smatch12 =
1354
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1355
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1356
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1357
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1358
                dbg_ctrl[23:22]==2'b11)
1359
                ;
1360
wire dbg_smatch20 =
1361
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1362
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1363
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1364
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1365
                    dbg_ctrl[27:26]==2'b11)
1366
                    ;
1367
wire dbg_smatch21 =
1368
           dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1369
                    ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1370
                     (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1371
                     (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1372
                     dbg_ctrl[27:26]==2'b11)
1373
                     ;
1374
wire dbg_smatch22 =
1375
            dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1376
                     ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1377
                      (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1378
                      (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1379
                      dbg_ctrl[27:26]==2'b11)
1380
                      ;
1381
wire dbg_smatch30 =
1382
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1383
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1384
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1385
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1386
                      dbg_ctrl[31:30]==2'b11)
1387
                      ;
1388
wire dbg_smatch31 =
1389
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1390
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1391
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1392
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1393
                    dbg_ctrl[31:30]==2'b11)
1394
                    ;
1395
wire dbg_smatch32 =
1396
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1397
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1398
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1399
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1400
                    dbg_ctrl[31:30]==2'b11)
1401
                    ;
1402
wire dbg_smatch0 = dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30;
1403
wire dbg_smatch1 = dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31;
1404
wire dbg_smatch2 = dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32;
1405
 
1406
wire dbg_smatch =   dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30|
1407
                    dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31|
1408
                    dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32
1409
                    ;
1410
 
1411
wire dbg_stat0 = dbg_imatchA0 | dbg_imatchB0 | dbg_lmatch00 | dbg_lmatch01 | dbg_lmatch02 | dbg_smatch00 | dbg_smatch01 | dbg_smatch02;
1412
wire dbg_stat1 = dbg_imatchA1 | dbg_imatchB1 | dbg_lmatch10 | dbg_lmatch11 | dbg_lmatch12 | dbg_smatch10 | dbg_smatch11 | dbg_smatch12;
1413
wire dbg_stat2 = dbg_imatchA2 | dbg_imatchB2 | dbg_lmatch20 | dbg_lmatch21 | dbg_lmatch22 | dbg_smatch20 | dbg_smatch21 | dbg_smatch22;
1414
wire dbg_stat3 = dbg_imatchA3 | dbg_imatchB3 | dbg_lmatch30 | dbg_lmatch31 | dbg_lmatch32 | dbg_smatch30 | dbg_smatch31 | dbg_smatch32;
1415
assign dbg_stat1x = {dbg_stat3,dbg_stat2,dbg_stat1,dbg_stat0};
1416
wire debug_on = |dbg_ctrl[3:0]|dbg_ctrl[7]|dbg_ctrl[63];
1417
 
1418
always @*
1419
begin
1420
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf0_pc==dbg_adr0)
1421
        dbg_imatchA0 = `TRUE;
1422
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf0_pc==dbg_adr1)
1423
        dbg_imatchA1 = `TRUE;
1424
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf0_pc==dbg_adr2)
1425
        dbg_imatchA2 = `TRUE;
1426
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf0_pc==dbg_adr3)
1427
        dbg_imatchA3 = `TRUE;
1428
    if (dbg_imatchA0|dbg_imatchA1|dbg_imatchA2|dbg_imatchA3)
1429
        dbg_imatchA = `TRUE;
1430
end
1431
 
1432
always @*
1433
begin
1434
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf1_pc==dbg_adr0)
1435
        dbg_imatchB0 = `TRUE;
1436
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf1_pc==dbg_adr1)
1437
        dbg_imatchB1 = `TRUE;
1438
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf1_pc==dbg_adr2)
1439
        dbg_imatchB2 = `TRUE;
1440
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf1_pc==dbg_adr3)
1441
        dbg_imatchB3 = `TRUE;
1442
    if (dbg_imatchB0|dbg_imatchB1|dbg_imatchB2|dbg_imatchB3)
1443
        dbg_imatchB = `TRUE;
1444
end
1445
`endif
1446
 
1447
//-----------------------------------------------------------------------------
1448
//-----------------------------------------------------------------------------
1449
 
1450
// hirq squashes the pc increment if there's an irq.
1451
wire hirq = (irq_i > im) && ~int_commit;
1452
always @*
1453
if (hirq)
1454 49 robfinch
        insn0 <= {8'd0,3'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1455 48 robfinch
else if (phit) begin
1456 49 robfinch
        if (insn0a[`INSTRUCTION_OP]==`BRK && insn0a[23:21]==3'd0 && insn0a[7:6]==2'b00)
1457
                insn0 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1458 48 robfinch
        else
1459
                insn0 <= insn0a;
1460
end
1461
else
1462
        insn0 <= `NOP_INSN;
1463 49 robfinch
generate begin : gInsnMux
1464
if (`WAYS > 1) begin
1465 48 robfinch
always @*
1466
if (phit) begin
1467 49 robfinch
        if (insn1a[`INSTRUCTION_OP]==`BRK && insn1a[23:21]==3'd0 && insn1a[7:6]==2'b00)
1468
                insn1 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1469 48 robfinch
        else
1470
                insn1 <= insn1a;
1471
end
1472
else
1473
        insn1 <= `NOP_INSN;
1474 49 robfinch
end
1475
if (`WAYS > 2) begin
1476
always @*
1477
if (phit) begin
1478
        if (insn2a[`INSTRUCTION_OP]==`BRK && insn1a[23:21]==3'd0 && insn2a[7:6]==2'b00)
1479
                insn2 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1480
        else
1481
                insn2 <= insn2a;
1482
end
1483
else
1484
        insn2 <= `NOP_INSN;
1485
end
1486
end
1487
endgenerate
1488 48 robfinch
 
1489
wire [63:0] dc0_out, dc1_out, dc2_out;
1490
assign rdat0 = dram0_unc ? xdati : dc0_out;
1491
assign rdat1 = dram1_unc ? xdati : dc1_out;
1492
assign rdat2 = dram2_unc ? xdati : dc2_out;
1493
 
1494
reg preload;
1495
reg [1:0] dccnt;
1496
wire dhit0, dhit1, dhit2;
1497
wire dhit00, dhit10, dhit20;
1498
wire dhit01, dhit11, dhit21;
1499 49 robfinch
reg [`ABITS] dc_wadr;
1500 48 robfinch
reg [63:0] dc_wdat;
1501
reg isStore;
1502
 
1503
FT64_dcache udc0
1504
(
1505
    .rst(rst),
1506
    .wclk(clk),
1507
    .wr((bstate==B2d && ack_i)||((bstate==B1||(bstate==B19 && isStore)) && dhit0)),
1508
    .sel(sel_o),
1509
    .wadr({pcr[5:0],adr_o}),
1510
    .i(bstate==B2d ? dat_i : dat_o),
1511
    .rclk(clk),
1512
    .rdsize(dram0_memsize),
1513
    .radr({pcr[5:0],dram0_addr}),
1514
    .o(dc0_out),
1515
    .hit(),
1516
    .hit0(dhit0),
1517
    .hit1()
1518
);
1519 49 robfinch
generate begin : gDCacheInst
1520
if (`NUM_MEM > 1) begin
1521 48 robfinch
FT64_dcache udc1
1522
(
1523
    .rst(rst),
1524
    .wclk(clk),
1525
    .wr((bstate==B2d && ack_i)||((bstate==B1||(bstate==B19 && isStore)) && dhit1)),
1526
    .sel(sel_o),
1527
    .wadr({pcr[5:0],adr_o}),
1528
    .i(bstate==B2d ? dat_i : dat_o),
1529
    .rclk(clk),
1530
    .rdsize(dram1_memsize),
1531
    .radr({pcr[5:0],dram1_addr}),
1532
    .o(dc1_out),
1533
    .hit(),
1534
    .hit0(dhit1),
1535
    .hit1()
1536
);
1537 49 robfinch
end
1538
if (`NUM_MEM > 2) begin
1539 48 robfinch
FT64_dcache udc2
1540
(
1541
    .rst(rst),
1542
    .wclk(clk),
1543
    .wr((bstate==B2d && ack_i)||((bstate==B1||(bstate==B19 && isStore)) && dhit2)),
1544
    .sel(sel_o),
1545
    .wadr({pcr[5:0],adr_o}),
1546
    .i(bstate==B2d ? dat_i : dat_o),
1547
    .rclk(clk),
1548
    .rdsize(dram2_memsize),
1549
    .radr({pcr[5:0],dram2_addr}),
1550
    .o(dc2_out),
1551
    .hit(),
1552
    .hit0(dhit2),
1553
    .hit1()
1554
);
1555 49 robfinch
end
1556
end
1557
endgenerate
1558 48 robfinch
 
1559
function [`QBITS] idp1;
1560
input [`QBITS] id;
1561
case(id)
1562
3'd0:   idp1 = 3'd1;
1563
3'd1:   idp1 = 3'd2;
1564
3'd2:   idp1 = 3'd3;
1565
3'd3:   idp1 = 3'd4;
1566
3'd4:   idp1 = 3'd5;
1567
3'd5:   idp1 = 3'd6;
1568
3'd6:   idp1 = 3'd7;
1569
3'd7:   idp1 = 3'd0;
1570
endcase
1571
endfunction
1572
 
1573
function [`QBITS] idp2;
1574
input [`QBITS] id;
1575
case(id)
1576
3'd0:   idp2 = 3'd2;
1577
3'd1:   idp2 = 3'd3;
1578
3'd2:   idp2 = 3'd4;
1579
3'd3:   idp2 = 3'd5;
1580
3'd4:   idp2 = 3'd6;
1581
3'd5:   idp2 = 3'd7;
1582
3'd6:   idp2 = 3'd0;
1583
3'd7:   idp2 = 3'd1;
1584
endcase
1585
endfunction
1586
 
1587
function [`QBITS] idp3;
1588
input [`QBITS] id;
1589
case(id)
1590
3'd0:   idp3 = 3'd3;
1591
3'd1:   idp3 = 3'd4;
1592
3'd2:   idp3 = 3'd5;
1593
3'd3:   idp3 = 3'd6;
1594
3'd4:   idp3 = 3'd7;
1595
3'd5:   idp3 = 3'd0;
1596
3'd6:   idp3 = 3'd1;
1597
3'd7:   idp3 = 3'd2;
1598
endcase
1599
endfunction
1600
 
1601
function [`QBITS] idp4;
1602
input [`QBITS] id;
1603
case(id)
1604
3'd0:   idp4 = 3'd4;
1605
3'd1:   idp4 = 3'd5;
1606
3'd2:   idp4 = 3'd6;
1607
3'd3:   idp4 = 3'd7;
1608
3'd4:   idp4 = 3'd0;
1609
3'd5:   idp4 = 3'd1;
1610
3'd6:   idp4 = 3'd2;
1611
3'd7:   idp4 = 3'd3;
1612
endcase
1613
endfunction
1614
 
1615
function [`QBITS] idp5;
1616
input [`QBITS] id;
1617
case(id)
1618
3'd0:   idp5 = 3'd5;
1619
3'd1:   idp5 = 3'd6;
1620
3'd2:   idp5 = 3'd7;
1621
3'd3:   idp5 = 3'd0;
1622
3'd4:   idp5 = 3'd1;
1623
3'd5:   idp5 = 3'd2;
1624
3'd6:   idp5 = 3'd3;
1625
3'd7:   idp5 = 3'd4;
1626
endcase
1627
endfunction
1628
 
1629
function [`QBITS] idp6;
1630
input [`QBITS] id;
1631
case(id)
1632
3'd0:   idp6 = 3'd6;
1633
3'd1:   idp6 = 3'd7;
1634
3'd2:   idp6 = 3'd0;
1635
3'd3:   idp6 = 3'd1;
1636
3'd4:   idp6 = 3'd2;
1637
3'd5:   idp6 = 3'd3;
1638
3'd6:   idp6 = 3'd4;
1639
3'd7:   idp6 = 3'd5;
1640
endcase
1641
endfunction
1642
 
1643
function [`QBITS] idp7;
1644
input [`QBITS] id;
1645
case(id)
1646
3'd0:   idp7 = 3'd7;
1647
3'd1:   idp7 = 3'd0;
1648
3'd2:   idp7 = 3'd1;
1649
3'd3:   idp7 = 3'd2;
1650
3'd4:   idp7 = 3'd3;
1651
3'd5:   idp7 = 3'd4;
1652
3'd6:   idp7 = 3'd5;
1653
3'd7:   idp7 = 3'd6;
1654
endcase
1655
endfunction
1656
 
1657
function [`QBITS] idm1;
1658
input [`QBITS] id;
1659
case(id)
1660
3'd0:   idm1 = 3'd7;
1661
3'd1:   idm1 = 3'd0;
1662
3'd2:   idm1 = 3'd1;
1663
3'd3:   idm1 = 3'd2;
1664
3'd4:   idm1 = 3'd3;
1665
3'd5:   idm1 = 3'd4;
1666
3'd6:   idm1 = 3'd5;
1667
3'd7:   idm1 = 3'd6;
1668
endcase
1669
endfunction
1670
 
1671
`ifdef SUPPORT_SMT
1672
function [RBIT:0] fnRa;
1673
input [47:0] isn;
1674
input [5:0] vqei;
1675
input [5:0] vli;
1676
input thrd;
1677
case(isn[`INSTRUCTION_OP])
1678
`IVECTOR:
1679
        case(isn[`INSTRUCTION_S2])
1680
        `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1681
        `VMxx:
1682
                case(isn[25:23])
1683
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
1684
                    fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1685
            `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1686
            default:fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1687
            endcase
1688
        `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
1689
        `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
1690
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1691
        default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1692
        endcase
1693 50 robfinch
`R2:    casez(isn[`INSTRUCTION_S2])
1694 48 robfinch
                `MOV:
1695
                        case(isn[25:23])
1696
                        3'd0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1697 50 robfinch
                        3'd1:   fnRa = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
1698 48 robfinch
                        3'd2:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1699
                        3'd3:   fnRa = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RA]};
1700
                        3'd4:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1701 49 robfinch
                        3'd5:   fnRa = {fp1_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1702
                        3'd6:   fnRa = {fp1_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1703 48 robfinch
                        default:fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1704
                        endcase
1705
        `VMOV:
1706
            case (isn[`INSTRUCTION_S1])
1707
            5'h0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1708
            5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
1709
            endcase
1710
        default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1711
        endcase
1712 49 robfinch
`FLOAT:         fnRa = {fp1_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1713 48 robfinch
default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1714
endcase
1715
endfunction
1716
 
1717
function [RBIT:0] fnRb;
1718
input [47:0] isn;
1719
input fb;
1720
input [5:0] vqei;
1721
input [5:0] rfoa0i;
1722
input [5:0] rfoa1i;
1723
input thrd;
1724
case(isn[`INSTRUCTION_OP])
1725
`R2:        case(isn[`INSTRUCTION_S2])
1726
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
1727
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1728
            default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1729
            endcase
1730
`IVECTOR:
1731
                        case(isn[`INSTRUCTION_S2])
1732
                        `VMxx:
1733
                                case(isn[25:23])
1734
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
1735
                        fnRb = {6'h3F,1'b1,2'b0,isn[13:11]};
1736
                default:        fnRb = 12'h000;
1737
                endcase
1738
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1739
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1740
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
1741
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
1742
                fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1743
            `VSHL,`VSHR,`VASR:
1744
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
1745
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1746
            endcase
1747 49 robfinch
`FLOAT:         fnRb = {fp1_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1748 48 robfinch
default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1749
endcase
1750
endfunction
1751
 
1752
function [RBIT:0] fnRc;
1753
input [47:0] isn;
1754
input [5:0] vqei;
1755
input thrd;
1756
case(isn[`INSTRUCTION_OP])
1757
`R2:        case(isn[`INSTRUCTION_S2])
1758
            `SVX:       fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1759
                `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1760
                        fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1761
                `CMOVEZ,`CMOVNZ,`MAJ:
1762
                        fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1763
            default:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1764
            endcase
1765
`IVECTOR:
1766
                        case(isn[`INSTRUCTION_S2])
1767
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[18:16]};
1768
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1769
            endcase
1770 49 robfinch
`FLOAT:         fnRc = {fp1_rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1771 48 robfinch
default:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1772
endcase
1773
endfunction
1774
 
1775
function [RBIT:0] fnRt;
1776
input [47:0] isn;
1777
input [5:0] vqei;
1778
input [5:0] vli;
1779
input thrd;
1780
casez(isn[`INSTRUCTION_OP])
1781
`IVECTOR:
1782
                case(isn[`INSTRUCTION_S2])
1783
                `VMxx:
1784
                        case(isn[25:23])
1785
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
1786
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1787
            `VMPOP:     fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1788
            default:
1789
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1790
            endcase
1791
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1792
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
1793
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
1794
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
1795
        `V2BITS:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1796
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1797
        endcase
1798
 
1799 50 robfinch
`R2:    casez(isn[`INSTRUCTION_S2])
1800 48 robfinch
                `MOV:
1801
                        case(isn[25:23])
1802 50 robfinch
                        3'd0:   fnRt = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RB]};
1803 48 robfinch
                        3'd1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1804
                        3'd2:   fnRt = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RB]};
1805
                        3'd3:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1806 49 robfinch
                        3'd4:   fnRt = {fp1_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1807 48 robfinch
                        3'd5:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1808 49 robfinch
                        3'd6:   fnRt = {fp1_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1809 48 robfinch
                        default:fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1810
                        endcase
1811
        `VMOV:
1812
            case (isn[`INSTRUCTION_S1])
1813
            5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RB]};
1814
            5'h1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1815
            default:    fnRt = 12'h000;
1816
            endcase
1817
        `R1:
1818
                case(isn[22:18])
1819
                `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT:
1820
                        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1821
                `MEMDB,`MEMSB,`SYNC:
1822
                        fnRt = 12'd0;
1823
                default:        fnRt = 12'd0;
1824
                endcase
1825
        `CMOVEZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1826
        `CMOVNZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1827
        `MUX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1828
        `MIN:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1829
        `MAX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1830
        `LVX:       fnRt = {vqei,1'b1,isn[20:16]};
1831
        `SHIFTR:        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1832
        `SHIFT31,`SHIFT63:
1833
                                fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1834
        `SEI:           fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1835
        `WAIT,`RTI,`CHK:
1836
                        fnRt = 12'd0;
1837
                default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1838
        endcase
1839
`MEMNDX:
1840
    case(isn[`INSTRUCTION_S2])
1841
    `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1842
                        fnRt = 12'd0;
1843
    default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1844
        endcase
1845
`FLOAT:
1846
                case(isn[31:26])
1847
                `FTX,`FCX,`FEX,`FDX,`FRM:
1848
                                        fnRt = 12'd0;
1849
                `FSYNC:         fnRt = 12'd0;
1850 49 robfinch
                default:        fnRt = {fp1_rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1851 48 robfinch
                endcase
1852
`BRK:   fnRt = 12'd0;
1853
`REX:   fnRt = 12'd0;
1854
`CHK:   fnRt = 12'd0;
1855
`EXEC:  fnRt = 12'd0;
1856
`Bcc:   fnRt = 12'd0;
1857
`BBc:   case(isn[20:19])
1858
                `IBNE:  fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1859
                `DBNZ:  fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1860
                default:        fnRt = 12'd0;
1861
                endcase
1862
`BEQI:  fnRt = 12'd0;
1863
`SB,`Sx,`SWC,`CACHE:
1864
                fnRt = 12'd0;
1865
`JMP:   fnRt = 12'd0;
1866
`CALL:  fnRt = {rgs[thrd],1'b0,regLR};  // regLR
1867
`RET:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1868
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1869
`AMO:   fnRt = isn[31] ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]} : {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1870
default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1871
endcase
1872
endfunction
1873
`else
1874
function [RBIT:0] fnRa;
1875
input [47:0] isn;
1876
input [5:0] vqei;
1877
input [5:0] vli;
1878
input thrd;
1879
case(isn[`INSTRUCTION_OP])
1880
`IVECTOR:
1881
        case(isn[`INSTRUCTION_S2])
1882
        `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1883
        `VMxx:
1884
                case(isn[25:23])
1885
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
1886
                    fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1887
            `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1888
            default:fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1889
            endcase
1890
        `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
1891
        `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
1892
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1893
        default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1894
        endcase
1895 50 robfinch
`R2:
1896
        casez(isn[`INSTRUCTION_S2])
1897
        `MOV:
1898
                case(isn[25:23])
1899
                3'd0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1900
                3'd1:   fnRa = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
1901
                3'd2:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1902
                3'd3:   fnRa = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RA]};
1903
                3'd4:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1904
                3'd5:   fnRa = {fp1_rgs,1'b0,isn[`INSTRUCTION_RA]};
1905
                3'd6:   fnRa = {fp1_rgs,1'b0,isn[`INSTRUCTION_RA]};
1906
                default:fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1907
                endcase
1908
  `VMOV:
1909
    case (isn[`INSTRUCTION_S1])
1910
    5'h0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1911
    5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
1912
    endcase
1913
  default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1914
  endcase
1915 49 robfinch
`FLOAT:         fnRa = {fp1_rgs,1'b0,isn[`INSTRUCTION_RA]};
1916 48 robfinch
default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1917
endcase
1918
endfunction
1919
 
1920
function [RBIT:0] fnRb;
1921
input [47:0] isn;
1922
input fb;
1923
input [5:0] vqei;
1924
input [5:0] rfoa0i;
1925
input [5:0] rfoa1i;
1926
input thrd;
1927
case(isn[`INSTRUCTION_OP])
1928
`RR:        case(isn[`INSTRUCTION_S2])
1929
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
1930
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1931
            default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1932
            endcase
1933
`IVECTOR:
1934
                        case(isn[`INSTRUCTION_S2])
1935
                        `VMxx:
1936
                                case(isn[25:23])
1937
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
1938
                        fnRb = {6'h3F,1'b1,2'b0,isn[13:11]};
1939
                default:        fnRb = 12'h000;
1940
                endcase
1941
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1942
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1943
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
1944
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
1945
                fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1946
            `VSHL,`VSHR,`VASR:
1947
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs,1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
1948
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1949
            endcase
1950 49 robfinch
`FLOAT:         fnRb = {fp1_rgs,1'b0,isn[`INSTRUCTION_RB]};
1951 48 robfinch
default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1952
endcase
1953
endfunction
1954
 
1955
function [RBIT:0] fnRc;
1956
input [47:0] isn;
1957
input [5:0] vqei;
1958
input thrd;
1959
case(isn[`INSTRUCTION_OP])
1960
`R2:        case(isn[`INSTRUCTION_S2])
1961
            `SVX:       fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1962
                `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1963
                        fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1964
                `CMOVEZ,`CMOVNZ,`MAJ:
1965
                        fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1966
            default:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1967
            endcase
1968
`IVECTOR:
1969
                        case(isn[`INSTRUCTION_S2])
1970
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[18:16]};
1971
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1972
            endcase
1973 49 robfinch
`FLOAT:         fnRc = {fp1_rgs,1'b0,isn[`INSTRUCTION_RC]};
1974 48 robfinch
default:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1975
endcase
1976
endfunction
1977
 
1978
function [RBIT:0] fnRt;
1979
input [47:0] isn;
1980
input [5:0] vqei;
1981
input [5:0] vli;
1982
input thrd;
1983
casez(isn[`INSTRUCTION_OP])
1984
`IVECTOR:
1985
                case(isn[`INSTRUCTION_S2])
1986
                `VMxx:
1987
                        case(isn[25:23])
1988
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
1989
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1990
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1991
            default:
1992
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1993
            endcase
1994
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1995
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
1996
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
1997
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
1998
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1999
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2000
        endcase
2001
 
2002
`FVECTOR:
2003
                case(isn[`INSTRUCTION_S2])
2004
                `VMxx:
2005
                        case(isn[25:23])
2006
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
2007
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2008
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2009
            default:
2010
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2011
            endcase
2012
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2013
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
2014
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
2015
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
2016
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2017
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2018
        endcase
2019
 
2020 50 robfinch
`R2:
2021
        casez(isn[`INSTRUCTION_S2])
2022
        `MOV:
2023
                case(isn[25:23])
2024
                3'd0:   fnRt = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RB]};
2025
                3'd1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2026
                3'd2:   fnRt = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RB]};
2027
                3'd3:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2028
                3'd4:   fnRt = {fp1_rgs,1'b0,isn[`INSTRUCTION_RB]};
2029
                3'd5:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2030
                3'd6:   fnRt = {fp1_rgs,1'b0,isn[`INSTRUCTION_RB]};
2031
                default:fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2032
                endcase
2033
  `VMOV:
2034
    case (isn[`INSTRUCTION_S1])
2035
    5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RB]};
2036
    5'h1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2037
    default:    fnRt = 12'h000;
2038
    endcase
2039
  `R1:
2040
        case(isn[22:18])
2041
        `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT:
2042
                fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2043
        `MEMDB,`MEMSB,`SYNC:
2044
                fnRt = 12'd0;
2045
        default:        fnRt = 12'd0;
2046
        endcase
2047
  `CMOVEZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2048
  `CMOVNZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2049
  `MUX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2050
  `MIN:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2051
  `MAX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2052
  `LVX:       fnRt = {vqei,1'b1,isn[20:16]};
2053
  `SHIFTR:      fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2054
  `SHIFT31,`SHIFT63:
2055
                        fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2056
  `SEI:         fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2057
  `WAIT,`RTI,`CHK:
2058
                        fnRt = 12'd0;
2059
  default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2060
  endcase
2061 48 robfinch
`MEMNDX:
2062
        case(isn[`INSTRUCTION_S2])
2063
  `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
2064
                        fnRt = 12'd0;
2065
  default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2066
  endcase
2067
`FLOAT:
2068
                case(isn[31:26])
2069
                `FTX,`FCX,`FEX,`FDX,`FRM:
2070
                                        fnRt = 12'd0;
2071
                `FSYNC:         fnRt = 12'd0;
2072 49 robfinch
                default:        fnRt = {fp1_rgs,1'b0,isn[`INSTRUCTION_RC]};
2073 48 robfinch
                endcase
2074
`BRK:   fnRt = 12'd0;
2075
`REX:   fnRt = 12'd0;
2076
`CHK:   fnRt = 12'd0;
2077
`EXEC:  fnRt = 12'd0;
2078
`Bcc:   fnRt = 12'd0;
2079
`BBc:
2080
        case(isn[20:19])
2081
        `IBNE:  fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2082
        `DBNZ:  fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2083
        default:        fnRt = 12'd0;
2084
        endcase
2085
`BEQI:  fnRt = 12'd0;
2086
`SB,`Sx,`SWC,`CACHE:
2087
                fnRt = 12'd0;
2088
`JMP:   fnRt = 12'd0;
2089
`CALL:  fnRt = {rgs,1'b0,regLR};        // regLR
2090
`RET:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2091
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2092
`AMO:   fnRt = isn[31] ? {rgs,1'b0,isn[`INSTRUCTION_RB]} : {rgs,1'b0,isn[`INSTRUCTION_RC]};
2093
default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2094
endcase
2095
endfunction
2096
`endif
2097
 
2098
// Determines which lanes of the target register get updated.
2099
function [7:0] fnWe;
2100
input [47:0] isn;
2101
casez(isn[`INSTRUCTION_OP])
2102
`R2:
2103
        case(isn[`INSTRUCTION_S2])
2104
        `R1:
2105
                case(isn[22:18])
2106
                `ABS,`CNTLZ,`CNTLO,`CNTPOP:
2107
                        case(isn[25:23])
2108
                        3'b000: fnWe = 8'h01;
2109
                        3'b001: fnWe = 8'h03;
2110
                        3'b010: fnWe = 8'h0F;
2111
                        3'b011: fnWe = 8'hFF;
2112
                        default:        fnWe = 8'hFF;
2113
                        endcase
2114
                default: fnWe = 8'hFF;
2115
                endcase
2116
        `SHIFT31:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
2117
        `SHIFT63:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
2118
        `SLT,`SLTU,`SLE,`SLEU,
2119
        `ADD,`SUB,
2120
        `AND,`OR,`XOR,
2121
        `NAND,`NOR,`XNOR,
2122 50 robfinch
        `DIV,`DIVU,`DIVSU,
2123
        `MOD,`MODU,`MODSU,
2124
        `MUL,`MULU,`MULSU,
2125
        `MULH,`MULUH,`MULSUH:
2126 48 robfinch
                case(isn[25:23])
2127
                3'b000: fnWe = 8'h01;
2128
                3'b001: fnWe = 8'h03;
2129
                3'b010: fnWe = 8'h0F;
2130
                3'b011: fnWe = 8'hFF;
2131
                default:        fnWe = 8'hFF;
2132
                endcase
2133
        default: fnWe = 8'hFF;
2134
        endcase
2135
default:        fnWe = 8'hFF;
2136
endcase
2137
endfunction
2138
 
2139
// Detect if a source is automatically valid
2140
function Source1Valid;
2141
input [47:0] isn;
2142
casez(isn[`INSTRUCTION_OP])
2143
`BRK:   Source1Valid = TRUE;
2144
`Bcc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2145
`BBc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2146
`BEQI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2147
`CHK:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2148
`RR:    case(isn[`INSTRUCTION_S2])
2149
        `SHIFT31:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2150
        `SHIFT63:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2151
        `SHIFTR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2152
        default:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2153
        endcase
2154
`MEMNDX:Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2155
`ADDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2156
`SLTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2157
`SLTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2158
`SGTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2159
`SGTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2160
`ANDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2161
`ORI:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2162
`XORI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2163
`XNORI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2164
`MULUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2165
`AMO:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2166
`LB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2167
`LBU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2168
`Lx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2169
`LxU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2170
`LWR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2171
`LV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2172
`LVx:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2173
`SB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2174
`Sx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2175
`SWC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2176
`SV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2177
`INC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2178
`CAS:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2179
`JAL:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2180
`RET:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2181
`CSRRW: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2182
`BITFIELD:      case(isn[31:28])
2183
                        `BFINSI:        Source1Valid = TRUE;
2184
                        default:        Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2185
                        endcase
2186
`IVECTOR:
2187
                        Source1Valid = FALSE;
2188
default:    Source1Valid = TRUE;
2189
endcase
2190
endfunction
2191
 
2192
function Source2Valid;
2193
input [47:0] isn;
2194
casez(isn[`INSTRUCTION_OP])
2195
`BRK:   Source2Valid = TRUE;
2196
`Bcc:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2197
`BBc:   Source2Valid = TRUE;
2198
`BEQI:  Source2Valid = TRUE;
2199
`CHK:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2200
`RR:    case(isn[`INSTRUCTION_S2])
2201
        `R1:       Source2Valid = TRUE;
2202
        `SHIFTR:   Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2203
        `SHIFT31:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2204
        `SHIFT63:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2205
        `LVX,`SVX: Source2Valid = FALSE;
2206
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2207
        endcase
2208
`MEMNDX:
2209
        case(isn[`INSTRUCTION_S2])
2210
        `LVX,`SVX: Source2Valid = FALSE;
2211
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2212
        endcase
2213
`ADDI:  Source2Valid = TRUE;
2214
`SLTI:  Source2Valid = TRUE;
2215
`SLTUI: Source2Valid = TRUE;
2216
`SGTI:  Source2Valid = TRUE;
2217
`SGTUI: Source2Valid = TRUE;
2218
`ANDI:  Source2Valid = TRUE;
2219
`ORI:   Source2Valid = TRUE;
2220
`XORI:  Source2Valid = TRUE;
2221
`XNORI: Source2Valid = TRUE;
2222
`MULUI: Source2Valid = TRUE;
2223
`LB:    Source2Valid = TRUE;
2224
`LBU:   Source2Valid = TRUE;
2225
`Lx:    Source2Valid = TRUE;
2226
`LxU:   Source2Valid = TRUE;
2227
`LWR:   Source2Valid = TRUE;
2228
`LVx:   Source2Valid = TRUE;
2229
`INC:           Source2Valid = TRUE;
2230
`SB:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2231
`Sx:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2232
`SWC:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2233
`CAS:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2234
`JAL:   Source2Valid = TRUE;
2235
`RET:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2236
`IVECTOR:
2237
                    case(isn[`INSTRUCTION_S2])
2238
            `VABS:  Source2Valid = TRUE;
2239
            `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2240
                Source2Valid = FALSE;
2241
            `VADDS,`VSUBS,`VANDS,`VORS,`VXORS:
2242
                Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2243
            `VBITS2V:   Source2Valid = TRUE;
2244
            `V2BITS:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2245
            `VSHL,`VSHR,`VASR:  Source2Valid = isn[22:21]==2'd2;
2246
            default:    Source2Valid = FALSE;
2247
            endcase
2248
`LV:        Source2Valid = TRUE;
2249
`SV:        Source2Valid = FALSE;
2250
`AMO:           Source2Valid = isn[31] || isn[`INSTRUCTION_RB]==5'd0;
2251
default:    Source2Valid = TRUE;
2252
endcase
2253
endfunction
2254
 
2255
function Source3Valid;
2256
input [47:0] isn;
2257
case(isn[`INSTRUCTION_OP])
2258
`IVECTOR:
2259
    case(isn[`INSTRUCTION_S2])
2260
    `VEX:       Source3Valid = TRUE;
2261
    default:    Source3Valid = TRUE;
2262
    endcase
2263
`CHK:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2264
`R2:
2265
        if (isn[`INSTRUCTION_L2]==2'b01)
2266
                case(isn[47:42])
2267
    `CMOVEZ,`CMOVNZ:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2268
                default:        Source3Valid = TRUE;
2269
                endcase
2270
        else
2271
    case(isn[`INSTRUCTION_S2])
2272
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2273
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2274
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2275
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2276
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2277
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2278
    `MAJ:               Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2279
    default:    Source3Valid = TRUE;
2280
    endcase
2281
`MEMNDX:
2282
        if (isn[`INSTRUCTION_L2]==2'b00)
2283
    case(isn[`INSTRUCTION_S2])
2284
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2285
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2286
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2287
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2288
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2289
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2290
    default:    Source3Valid = TRUE;
2291
    endcase
2292
default:    Source3Valid = TRUE;
2293
endcase
2294
endfunction
2295
 
2296
function SourceTValid;
2297
input [31:0] isn;
2298
SourceTValid = FALSE;
2299
endfunction
2300
function SourceT2Valid;
2301
input [31:0] isn;
2302
case(isn[`INSTRUCTION_OP])
2303
`Bcc:       SourceT2Valid = TRUE;
2304
`ORI:       SourceT2Valid = TRUE;
2305
default:    SourceT2Valid = FALSE;
2306
endcase
2307
endfunction
2308
 
2309
// Used to indicate to the queue logic that the instruction needs to be
2310
// recycled to the queue VL number of times.
2311
function IsVector;
2312
input [47:0] isn;
2313
case(isn[`INSTRUCTION_OP])
2314
`MEMNDX:    case(isn[`INSTRUCTION_S2])
2315
            `LVX,`SVX:  IsVector = TRUE;
2316
            default:    IsVector = FALSE;
2317
            endcase
2318
`IVECTOR:
2319
                        case(isn[`INSTRUCTION_S2])
2320
                        `VMxx:
2321
                                case(isn[25:23])
2322
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2323
                        IsVector = FALSE;
2324
                default:        IsVector = TRUE;
2325
                endcase
2326
            `VEINS:     IsVector = FALSE;
2327
            `VEX:       IsVector = FALSE;
2328
            default:    IsVector = TRUE;
2329
            endcase
2330
`LV,`SV:    IsVector = TRUE;
2331
default:    IsVector = FALSE;
2332
endcase
2333
endfunction
2334
 
2335
function IsVeins;
2336
input [47:0] isn;
2337
case(isn[`INSTRUCTION_OP])
2338
`IVECTOR:   IsVeins = isn[`INSTRUCTION_S2]==`VEINS;
2339
default:    IsVeins = FALSE;
2340
endcase
2341
endfunction
2342
 
2343
function IsVex;
2344
input [47:0] isn;
2345
case(isn[`INSTRUCTION_OP])
2346
`IVECTOR:   IsVex = isn[`INSTRUCTION_S2]==`VEX;
2347
default:    IsVex = FALSE;
2348
endcase
2349
endfunction
2350
 
2351
function IsVCmprss;
2352
input [47:0] isn;
2353
case(isn[`INSTRUCTION_OP])
2354
`IVECTOR:   IsVCmprss = isn[`INSTRUCTION_S2]==`VCMPRSS || isn[`INSTRUCTION_S2]==`VCIDX;
2355
default:    IsVCmprss = FALSE;
2356
endcase
2357
endfunction
2358
 
2359
function IsVShifti;
2360
input [47:0] isn;
2361
case(isn[`INSTRUCTION_OP])
2362
`IVECTOR:
2363
                    case(isn[`INSTRUCTION_S2])
2364
            `VSHL,`VSHR,`VASR:
2365
                IsVShifti = {isn[25],isn[22]}==2'd2;
2366
            default:    IsVShifti = FALSE;
2367
            endcase
2368
default:    IsVShifti = FALSE;
2369
endcase
2370
endfunction
2371
 
2372
function IsVLS;
2373
input [47:0] isn;
2374
case(isn[`INSTRUCTION_OP])
2375
`MEMNDX:
2376
    case(isn[`INSTRUCTION_S2])
2377
    `LVX,`SVX,`LVWS,`SVWS:  IsVLS = TRUE;
2378
    default:    IsVLS = FALSE;
2379
    endcase
2380
`LV,`SV:    IsVLS = TRUE;
2381
default:    IsVLS = FALSE;
2382
endcase
2383
endfunction
2384
 
2385
function [1:0] fnM2;
2386
input [31:0] isn;
2387
case(isn[`INSTRUCTION_OP])
2388
`RR:    fnM2 = isn[24:23];
2389
default:    fnM2 = 2'b00;
2390
endcase
2391
endfunction
2392
 
2393
function [0:0] IsMem;
2394
input [47:0] isn;
2395
case(isn[`INSTRUCTION_OP])
2396
`MEMNDX:        IsMem = TRUE;
2397
`AMO:   IsMem = TRUE;
2398
`LB:    IsMem = TRUE;
2399
`LBU:   IsMem = TRUE;
2400
`Lx:    IsMem = TRUE;
2401
`LxU:   IsMem = TRUE;
2402
`LWR:   IsMem = TRUE;
2403
`LV,`SV:    IsMem = TRUE;
2404
`INC:           IsMem = TRUE;
2405
`SB:    IsMem = TRUE;
2406
`Sx:    IsMem = TRUE;
2407
`SWC:   IsMem = TRUE;
2408
`CAS:   IsMem = TRUE;
2409
`LVx:           IsMem = TRUE;
2410
default:    IsMem = FALSE;
2411
endcase
2412
endfunction
2413
 
2414
function IsMemNdx;
2415
input [47:0] isn;
2416
case(isn[`INSTRUCTION_OP])
2417
`MEMNDX:        IsMemNdx = TRUE;
2418
default:    IsMemNdx = FALSE;
2419
endcase
2420
endfunction
2421
 
2422
function IsLoad;
2423
input [47:0] isn;
2424
case(isn[`INSTRUCTION_OP])
2425
`MEMNDX:
2426
        if (isn[`INSTRUCTION_L2]==2'b00)
2427 50 robfinch
    case(isn[`INSTRUCTION_S2])
2428
    `LBX:   IsLoad = TRUE;
2429
    `LBUX:  IsLoad = TRUE;
2430
    `LCX:   IsLoad = TRUE;
2431
    `LCUX:  IsLoad = TRUE;
2432
    `LHX:   IsLoad = TRUE;
2433
    `LHUX:  IsLoad = TRUE;
2434
    `LWX:   IsLoad = TRUE;
2435
    `LVBX:      IsLoad = TRUE;
2436
    `LVBUX: IsLoad = TRUE;
2437
    `LVCX:  IsLoad = TRUE;
2438
    `LVCUX: IsLoad = TRUE;
2439
    `LVHX:  IsLoad = TRUE;
2440
    `LVHUX: IsLoad = TRUE;
2441
    `LVWX:  IsLoad = TRUE;
2442
    `LWRX:  IsLoad = TRUE;
2443
    `LVX:   IsLoad = TRUE;
2444
    `LVx:       IsLoad = TRUE;
2445
    default: IsLoad = FALSE;
2446
    endcase
2447 48 robfinch
        else
2448
                IsLoad = FALSE;
2449
`LB:    IsLoad = TRUE;
2450
`LBU:   IsLoad = TRUE;
2451
`Lx:    IsLoad = TRUE;
2452
`LxU:   IsLoad = TRUE;
2453
`LWR:   IsLoad = TRUE;
2454
`LV:    IsLoad = TRUE;
2455
`LVx:   IsLoad = TRUE;
2456
default:    IsLoad = FALSE;
2457
endcase
2458
endfunction
2459
 
2460
function IsInc;
2461
input [47:0] isn;
2462
case(isn[`INSTRUCTION_OP])
2463
`MEMNDX:
2464
        if (isn[`INSTRUCTION_L2]==2'b00)
2465
                case(isn[`INSTRUCTION_S2])
2466
            `INC:   IsInc = TRUE;
2467
            default:    IsInc = FALSE;
2468
            endcase
2469
        else
2470
                IsInc = FALSE;
2471
`INC:    IsInc = TRUE;
2472
default:    IsInc = FALSE;
2473
endcase
2474
endfunction
2475
 
2476
function IsSWC;
2477
input [47:0] isn;
2478
case(isn[`INSTRUCTION_OP])
2479
`MEMNDX:
2480
        if (isn[`INSTRUCTION_L2]==2'b00)
2481
                case(isn[`INSTRUCTION_S2])
2482
            `SWCX:   IsSWC = TRUE;
2483
            default:    IsSWC = FALSE;
2484
            endcase
2485
        else
2486
                IsSWC = FALSE;
2487
`SWC:    IsSWC = TRUE;
2488
default:    IsSWC = FALSE;
2489
endcase
2490
endfunction
2491
 
2492
// Aquire / release bits are only available on indexed SWC / LWR
2493
function IsSWCX;
2494
input [47:0] isn;
2495
case(isn[`INSTRUCTION_OP])
2496
`MEMNDX:
2497
        if (isn[`INSTRUCTION_L2]==2'b00)
2498
            case(isn[`INSTRUCTION_S2])
2499
            `SWCX:   IsSWCX = TRUE;
2500
            default:    IsSWCX = FALSE;
2501
            endcase
2502
        else
2503
                IsSWCX = FALSE;
2504
default:    IsSWCX = FALSE;
2505
endcase
2506
endfunction
2507
 
2508
function IsLWR;
2509
input [47:0] isn;
2510
case(isn[`INSTRUCTION_OP])
2511
`MEMNDX:
2512
        if (isn[`INSTRUCTION_L2]==2'b00)
2513
            case(isn[`INSTRUCTION_S2])
2514
            `LWRX:   IsLWR = TRUE;
2515
            default:    IsLWR = FALSE;
2516
            endcase
2517
        else
2518
                IsLWR = FALSE;
2519
`LWR:    IsLWR = TRUE;
2520
default:    IsLWR = FALSE;
2521
endcase
2522
endfunction
2523
 
2524
function IsLWRX;
2525
input [47:0] isn;
2526
case(isn[`INSTRUCTION_OP])
2527
`MEMNDX:
2528
        if (isn[`INSTRUCTION_L2]==2'b00)
2529
            case(isn[`INSTRUCTION_S2])
2530
            `LWRX:   IsLWRX = TRUE;
2531
            default:    IsLWRX = FALSE;
2532
            endcase
2533
        else
2534
                IsLWRX = FALSE;
2535
default:    IsLWRX = FALSE;
2536
endcase
2537
endfunction
2538
 
2539
function IsCAS;
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
            `CASX:   IsCAS = TRUE;
2546
            default:    IsCAS = FALSE;
2547
            endcase
2548
        else
2549
                IsCAS = FALSE;
2550
`CAS:       IsCAS = TRUE;
2551
default:    IsCAS = FALSE;
2552
endcase
2553
endfunction
2554
 
2555
function IsAMO;
2556
input [47:0] isn;
2557
case(isn[`INSTRUCTION_OP])
2558
`AMO:       IsAMO = TRUE;
2559
default:    IsAMO = FALSE;
2560
endcase
2561
endfunction
2562
 
2563
// Really IsPredictableBranch
2564
// Does not include BccR's
2565
function IsBranch;
2566
input [47:0] isn;
2567
casez(isn[`INSTRUCTION_OP])
2568
`Bcc:   IsBranch = TRUE;
2569
`BBc:   IsBranch = TRUE;
2570
`BEQI:  IsBranch = TRUE;
2571
`CHK:   IsBranch = TRUE;
2572
default:    IsBranch = FALSE;
2573
endcase
2574
endfunction
2575
 
2576
function IsWait;
2577
input [47:0] isn;
2578
IsWait = isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`WAIT;
2579
endfunction
2580
 
2581
function IsBrk;
2582
input [47:0] isn;
2583
IsBrk = isn[`INSTRUCTION_OP]==`BRK && isn[`INSTRUCTION_L2]==2'b00;
2584
endfunction
2585
 
2586
function IsIrq;
2587
input [47:0] isn;
2588
IsIrq = isn[`INSTRUCTION_OP]==`BRK && isn[`INSTRUCTION_L2]==2'b00 && isn[23:20]==4'h0;
2589
endfunction
2590
 
2591
function IsRTI;
2592
input [47:0] isn;
2593
IsRTI = isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`RTI;
2594
endfunction
2595
 
2596
function IsJAL;
2597
input [47:0] isn;
2598
IsJAL = isn[`INSTRUCTION_OP]==`JAL && isn[7]==1'b0;
2599
endfunction
2600
 
2601
function IsCall;
2602
input [47:0] isn;
2603
IsCall = isn[`INSTRUCTION_OP]==`CALL && isn[7]==1'b0;
2604
endfunction
2605
 
2606
function IsJmp;
2607
input [47:0] isn;
2608
IsJmp = isn[`INSTRUCTION_OP]==`JMP && isn[7]==1'b0;
2609
endfunction
2610
 
2611
function IsRet;
2612
input [47:0] isn;
2613
IsRet = isn[`INSTRUCTION_OP]==`RET && isn[7]==1'b0;
2614
endfunction
2615
 
2616
function IsFlowCtrl;
2617
input [47:0] isn;
2618
casez(isn[`INSTRUCTION_OP])
2619
`BRK:    IsFlowCtrl = TRUE;
2620 49 robfinch
`R2:    case(isn[`INSTRUCTION_S2])
2621 48 robfinch
        `RTI:   IsFlowCtrl = TRUE;
2622
        default:    IsFlowCtrl = FALSE;
2623
        endcase
2624
`Bcc:   IsFlowCtrl = TRUE;
2625
`BBc:           IsFlowCtrl = TRUE;
2626
`BEQI:  IsFlowCtrl = TRUE;
2627
`CHK:   IsFlowCtrl = TRUE;
2628
`JAL:   IsFlowCtrl = TRUE;
2629
`JMP:           IsFlowCtrl = TRUE;
2630
`CALL:  IsFlowCtrl = TRUE;
2631
`RET:   IsFlowCtrl = TRUE;
2632
default:    IsFlowCtrl = FALSE;
2633
endcase
2634
endfunction
2635
 
2636
function IsCache;
2637
input [47:0] isn;
2638
case(isn[`INSTRUCTION_OP])
2639
`MEMNDX:
2640
        if (isn[`INSTRUCTION_L2]==2'b00)
2641
            case(isn[`INSTRUCTION_S2])
2642
            `CACHEX:    IsCache = TRUE;
2643
            default:    IsCache = FALSE;
2644
            endcase
2645
        else
2646
                IsCache = FALSE;
2647
`CACHE: IsCache = TRUE;
2648
default: IsCache = FALSE;
2649
endcase
2650
endfunction
2651
 
2652
function [4:0] CacheCmd;
2653
input [47:0] isn;
2654
case(isn[`INSTRUCTION_OP])
2655
`MEMNDX:
2656
        if (isn[`INSTRUCTION_L2]==2'b00)
2657
            case(isn[`INSTRUCTION_S2])
2658
            `CACHEX:    CacheCmd = isn[22:18];
2659
            default:    CacheCmd = 5'd0;
2660
            endcase
2661
        else
2662
                CacheCmd = 5'd0;
2663
`CACHE: CacheCmd = isn[15:11];
2664
default: CacheCmd = 5'd0;
2665
endcase
2666
endfunction
2667
 
2668
function IsMemsb;
2669
input [47:0] isn;
2670
IsMemsb = (isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMSB);
2671
endfunction
2672
 
2673
function IsSEI;
2674
input [47:0] isn;
2675
IsSEI = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`SEI);
2676
endfunction
2677
 
2678
function IsLV;
2679
input [47:0] isn;
2680
case(isn[`INSTRUCTION_OP])
2681
`MEMNDX:
2682
        if (isn[`INSTRUCTION_L2]==2'b00)
2683
            case(isn[`INSTRUCTION_S2])
2684
            `LVX:   IsLV = TRUE;
2685
            default:    IsLV = FALSE;
2686
            endcase
2687
        else
2688
                IsLV = FALSE;
2689
`LV:        IsLV = TRUE;
2690
default:    IsLV = FALSE;
2691
endcase
2692
endfunction
2693
 
2694
function IsRFW;
2695
input [47:0] isn;
2696
input [5:0] vqei;
2697
input [5:0] vli;
2698
input thrd;
2699
if (fnRt(isn,vqei,vli,thrd)==12'd0)
2700
    IsRFW = FALSE;
2701
else
2702
casez(isn[`INSTRUCTION_OP])
2703
`IVECTOR:   IsRFW = TRUE;
2704
`FVECTOR:   IsRFW = TRUE;
2705
`R2:
2706
        if (isn[`INSTRUCTION_L2]==2'b00)
2707
            case(isn[`INSTRUCTION_S2])
2708
            `R1:    IsRFW = TRUE;
2709
            `ADD:   IsRFW = TRUE;
2710
            `SUB:   IsRFW = TRUE;
2711
            `SLT:   IsRFW = TRUE;
2712
            `SLTU:  IsRFW = TRUE;
2713
            `SLE:   IsRFW = TRUE;
2714
        `SLEU:  IsRFW = TRUE;
2715
            `AND:   IsRFW = TRUE;
2716
            `OR:    IsRFW = TRUE;
2717
            `XOR:   IsRFW = TRUE;
2718
            `MULU:  IsRFW = TRUE;
2719
            `MULSU: IsRFW = TRUE;
2720
            `MUL:   IsRFW = TRUE;
2721 50 robfinch
            `MULUH:  IsRFW = TRUE;
2722
            `MULSUH: IsRFW = TRUE;
2723
            `MULH:   IsRFW = TRUE;
2724
            `DIVU:  IsRFW = TRUE;
2725
            `DIVSU: IsRFW = TRUE;
2726
            `DIV:IsRFW = TRUE;
2727
            `MODU:  IsRFW = TRUE;
2728
            `MODSU: IsRFW = TRUE;
2729
            `MOD:IsRFW = TRUE;
2730 48 robfinch
            `MOV:       IsRFW = TRUE;
2731
            `VMOV:      IsRFW = TRUE;
2732
            `SHIFTR,`SHIFT31,`SHIFT63:
2733
                        IsRFW = TRUE;
2734
            `MIN,`MAX:    IsRFW = TRUE;
2735
            `SEI:       IsRFW = TRUE;
2736
            default:    IsRFW = FALSE;
2737
            endcase
2738
        else
2739
                IsRFW = FALSE;
2740
`MEMNDX:
2741
        if (isn[`INSTRUCTION_L2]==2'b00)
2742 50 robfinch
    case(isn[`INSTRUCTION_S2])
2743
    `LBX:   IsRFW = TRUE;
2744
    `LBUX:  IsRFW = TRUE;
2745
    `LCX:   IsRFW = TRUE;
2746
    `LCUX:  IsRFW = TRUE;
2747
    `LHX:   IsRFW = TRUE;
2748
    `LHUX:  IsRFW = TRUE;
2749
    `LWX:   IsRFW = TRUE;
2750
    `LVBX:  IsRFW = TRUE;
2751
    `LVBUX: IsRFW = TRUE;
2752
    `LVCX:  IsRFW = TRUE;
2753
    `LVCUX: IsRFW = TRUE;
2754
    `LVHX:  IsRFW = TRUE;
2755
    `LVHUX: IsRFW = TRUE;
2756
    `LVWX:  IsRFW = TRUE;
2757
    `LWRX:  IsRFW = TRUE;
2758
    `LVX:   IsRFW = TRUE;
2759
    `CASX:  IsRFW = TRUE;
2760
    default:    IsRFW = FALSE;
2761
    endcase
2762 48 robfinch
        else
2763
                IsRFW = FALSE;
2764
`BBc:
2765
        case(isn[20:19])
2766
        `IBNE:  IsRFW = TRUE;
2767
        `DBNZ:  IsRFW = TRUE;
2768
        default:        IsRFW = FALSE;
2769
        endcase
2770
`BITFIELD:  IsRFW = TRUE;
2771
`ADDI:      IsRFW = TRUE;
2772
`SLTI:      IsRFW = TRUE;
2773
`SLTUI:     IsRFW = TRUE;
2774
`SGTI:      IsRFW = TRUE;
2775
`SGTUI:     IsRFW = TRUE;
2776
`ANDI:      IsRFW = TRUE;
2777
`ORI:       IsRFW = TRUE;
2778
`XORI:      IsRFW = TRUE;
2779
`MULUI:     IsRFW = TRUE;
2780
`MULI:      IsRFW = TRUE;
2781
`DIVUI:     IsRFW = TRUE;
2782
`DIVI:      IsRFW = TRUE;
2783
`MODI:      IsRFW = TRUE;
2784
`JAL:       IsRFW = TRUE;
2785
`CALL:      IsRFW = TRUE;
2786
`RET:       IsRFW = TRUE;
2787
`LB:        IsRFW = TRUE;
2788
`LBU:       IsRFW = TRUE;
2789
`Lx:        IsRFW = TRUE;
2790
`LWR:       IsRFW = TRUE;
2791
`LV:        IsRFW = TRUE;
2792
`LVx:                           IsRFW = TRUE;
2793
`CAS:       IsRFW = TRUE;
2794
`AMO:                           IsRFW = TRUE;
2795
`CSRRW:                 IsRFW = TRUE;
2796
default:    IsRFW = FALSE;
2797
endcase
2798
endfunction
2799
 
2800
function IsShifti;
2801
input [47:0] isn;
2802
case(isn[`INSTRUCTION_OP])
2803
`R2:
2804
        if (isn[`INSTRUCTION_L2]==2'b00)
2805
            case(isn[`INSTRUCTION_S2])
2806
            `SHIFT31,`SHIFT63:
2807
                IsShifti = TRUE;
2808
            default: IsShifti = FALSE;
2809
            endcase
2810
    else
2811
        IsShifti = FALSE;
2812
default: IsShifti = FALSE;
2813
endcase
2814
endfunction
2815
 
2816
function IsRtop;
2817
input [47:0] isn;
2818
case(isn[`INSTRUCTION_OP])
2819
`R2:
2820
        if (isn[`INSTRUCTION_L2]==2'b01)
2821
            case(isn[47:42])
2822
            `RTOP: IsRtop = TRUE;
2823
            default: IsRtop = FALSE;
2824
            endcase
2825
    else
2826
        IsRtop = FALSE;
2827
default: IsRtop = FALSE;
2828
endcase
2829
endfunction
2830
 
2831
function IsMul;
2832
input [47:0] isn;
2833
case(isn[`INSTRUCTION_OP])
2834 50 robfinch
`R2:
2835 48 robfinch
        if (isn[`INSTRUCTION_L2]==2'b00)
2836 50 robfinch
    case(isn[`INSTRUCTION_S2])
2837
    `MULU,`MULSU,`MUL: IsMul = TRUE;
2838
    `MULUH,`MULSUH,`MULH: IsMul = TRUE;
2839
    default:    IsMul = FALSE;
2840
    endcase
2841 48 robfinch
        else
2842
                IsMul = FALSE;
2843
`MULUI,`MULI:  IsMul = TRUE;
2844
default:    IsMul = FALSE;
2845
endcase
2846
endfunction
2847
 
2848
function IsDivmod;
2849
input [47:0] isn;
2850
case(isn[`INSTRUCTION_OP])
2851 50 robfinch
`R2:
2852 48 robfinch
        if (isn[`INSTRUCTION_L2]==2'b00)
2853 50 robfinch
    case(isn[`INSTRUCTION_S2])
2854
    `DIVU,`DIVSU,`DIV: IsDivmod = TRUE;
2855
    `MODU,`MODSU,`MOD: IsDivmod = TRUE;
2856
    default: IsDivmod = FALSE;
2857
    endcase
2858 48 robfinch
        else
2859
                IsDivmod = FALSE;
2860
`DIVUI,`DIVI,`MODI:  IsDivmod = TRUE;
2861
default:    IsDivmod = FALSE;
2862
endcase
2863
endfunction
2864
 
2865
function IsExec;
2866
input [47:0] isn;
2867
case(isn[`INSTRUCTION_OP])
2868
`EXEC:  IsExec = TRUE;
2869
default:        IsExec = FALSE;
2870
endcase
2871
endfunction
2872
 
2873
function [7:0] fnSelect;
2874
input [47:0] ins;
2875 49 robfinch
input [`ABITS] adr;
2876 48 robfinch
begin
2877
        case(ins[`INSTRUCTION_OP])
2878
        `MEMNDX:
2879
                if (ins[`INSTRUCTION_L2]==2'b00)
2880
                   case(ins[`INSTRUCTION_S2])
2881
               `LBX,`LBUX,`SBX:
2882
                   case(adr[2:0])
2883
                   3'd0:    fnSelect = 8'h01;
2884
                   3'd1:    fnSelect = 8'h02;
2885
                   3'd2:    fnSelect = 8'h04;
2886
                   3'd3:    fnSelect = 8'h08;
2887
                   3'd4:    fnSelect = 8'h10;
2888
                   3'd5:    fnSelect = 8'h20;
2889
                   3'd6:    fnSelect = 8'h40;
2890
                   3'd7:    fnSelect = 8'h80;
2891
                   endcase
2892
                `LCX,`LCUX,`SCX:
2893
                    case(adr[2:1])
2894
                    2'd0:   fnSelect = 8'h03;
2895
                    2'd1:   fnSelect = 8'h0C;
2896
                    2'd2:   fnSelect = 8'h30;
2897
                    2'd3:   fnSelect = 8'hC0;
2898
                    endcase
2899
                `LHX,`LHUX,`SHX:
2900
                   case(adr[2])
2901
                   1'b0:    fnSelect = 8'h0F;
2902
                   1'b1:    fnSelect = 8'hF0;
2903
                   endcase
2904
               `INC,
2905
               `LWX,`SWX,`LWRX,`SWCX,`LVX,`SVX,`CASX:
2906
                   fnSelect = 8'hFF;
2907
               `LVx:   ;
2908
//                      case(ins[25:23])
2909
//                     `LVB,`LVBU:
2910
//                         case(adr[2:0])
2911
//                         3'd0:    fnSelect = 8'h01;
2912
//                         3'd1:    fnSelect = 8'h02;
2913
//                         3'd2:    fnSelect = 8'h04;
2914
//                         3'd3:    fnSelect = 8'h08;
2915
//                         3'd4:    fnSelect = 8'h10;
2916
//                         3'd5:    fnSelect = 8'h20;
2917
//                         3'd6:    fnSelect = 8'h40;
2918
//                         3'd7:    fnSelect = 8'h80;
2919
//                         endcase
2920
//                      `LVC,`LVCU:
2921
//                          case(adr[2:1])
2922
//                          2'd0:   fnSelect = 8'h03;
2923
//                          2'd1:   fnSelect = 8'h0C;
2924
//                          2'd2:   fnSelect = 8'h30;
2925
//                          2'd3:   fnSelect = 8'hC0;
2926
//                          endcase
2927
//                      `LVH,`LVHU:
2928
//                         case(adr[2])
2929
//                         1'b0:    fnSelect = 8'h0F;
2930
//                         1'b1:    fnSelect = 8'hF0;
2931
//                         endcase
2932
//                     `LVW:
2933
//                         fnSelect = 8'hFF;
2934
//                      endcase
2935
               default: fnSelect = 8'h00;
2936
                   endcase
2937
           else
2938
                fnSelect = 8'h00;
2939
    `LB,`LBU,`SB:
2940
                case(adr[2:0])
2941
                3'd0:   fnSelect = 8'h01;
2942
                3'd1:   fnSelect = 8'h02;
2943
                3'd2:   fnSelect = 8'h04;
2944
                3'd3:   fnSelect = 8'h08;
2945
                3'd4:   fnSelect = 8'h10;
2946
                3'd5:   fnSelect = 8'h20;
2947
                3'd6:   fnSelect = 8'h40;
2948
                3'd7:   fnSelect = 8'h80;
2949
                endcase
2950
    `Lx,`LxU,`Sx:
2951
        casez(ins[20:18])
2952
        3'b100: fnSelect = 8'hFF;
2953
        3'b?10: fnSelect = adr[2] ? 8'hF0 : 8'h0F;
2954
        3'b??1:
2955
        case(adr[2:1])
2956
        2'd0:   fnSelect = 8'h03;
2957
        2'd1:   fnSelect = 8'h0C;
2958
        2'd2:   fnSelect = 8'h30;
2959
        2'd3:   fnSelect = 8'hC0;
2960
        endcase
2961
      default: fnSelect = 8'h00;
2962
      endcase
2963
        `INC,
2964
        `LWR,`SWC,`CAS:   fnSelect = 8'hFF;
2965
        `LV,`SV:   fnSelect = 8'hFF;
2966
        `AMO:
2967
                case(ins[23:21])
2968
                3'd0:   fnSelect = {8'h01 << adr[2:0]};
2969
                3'd1:   fnSelect = {8'h03 << {adr[2:1],1'b0}};
2970
                3'd2:   fnSelect = {8'h0F << {adr[2],2'b00}};
2971
                3'd3:   fnSelect = 8'hFF;
2972
                default:        fnSelect = 8'hFF;
2973
                endcase
2974
//      `LVx:
2975
//       `LVB,`LVBU:
2976
//           case(adr[2:0])
2977
//           3'd0:    fnSelect = 8'h01;
2978
//           3'd1:    fnSelect = 8'h02;
2979
//           3'd2:    fnSelect = 8'h04;
2980
//           3'd3:    fnSelect = 8'h08;
2981
//           3'd4:    fnSelect = 8'h10;
2982
//           3'd5:    fnSelect = 8'h20;
2983
//           3'd6:    fnSelect = 8'h40;
2984
//           3'd7:    fnSelect = 8'h80;
2985
//           endcase
2986
//        `LVC,`LVCU:
2987
//            case(adr[2:1])
2988
//            2'd0:   fnSelect = 8'h03;
2989
//            2'd1:   fnSelect = 8'h0C;
2990
//            2'd2:   fnSelect = 8'h30;
2991
//            2'd3:   fnSelect = 8'hC0;
2992
//            endcase
2993
//      `LVH,`LVHU:
2994
//           case(adr[2])
2995
//           1'b0:    fnSelect = 8'h0F;
2996
//           1'b1:    fnSelect = 8'hF0;
2997
//           endcase
2998
//       `LVW:
2999
//           fnSelect = 8'hFF;
3000
        default:        fnSelect = 8'h00;
3001
        endcase
3002
end
3003
endfunction
3004
/*
3005
function [63:0] fnDatc;
3006
input [47:0] ins;
3007
input [63:0] dat;
3008
case(ins[`INSTRUCTION_OP])
3009
`R2:
3010
        if (isn[`INSTRUCTION_L2]==2'b01)
3011
                case(ins[47:42])
3012
                `FINDB:         fnDatc = dat[7:0];
3013
                `FINDC:         fnDatc = dat[15:0];
3014
                `FINDH:         fnDatc = dat[31:0];
3015
                `FINDW:         fnDatc = dat[63:0];
3016
                default:        fnDatc = dat[63:0];
3017
                endcase
3018
        else
3019
                fnDatc = dat[63:0];
3020
default:        fnDatc = dat[63:0];
3021
endcase
3022
endfunction
3023
*/
3024
/*
3025
function [63:0] fnMemInc;
3026
input [47:0] ins;
3027
case(ins[`INSTRUCTION_OP])
3028
`R2:
3029
        if (isn[`INSTRUCTION_L2]==2'b01)
3030
                case(ins[47:42])
3031
                `FINDB:         fnMemInc = 32'd1;
3032
                `FINDC:         fnMemInc = 32'd2;
3033
                `FINDH:         fnMemInc = 32'd4;
3034
                `FINDW:         fnMemInc = 32'd8;
3035
                default:        fnMemInc = 32'd8;
3036
                endcase
3037
        else
3038
                fnMemInc = 32'd8;
3039
default:        fnMemInc = 32'd8;
3040
endcase
3041
endfunction
3042
*/
3043
function [63:0] fnDati;
3044
input [47:0] ins;
3045 49 robfinch
input [`ABITS] adr;
3046 48 robfinch
input [63:0] dat;
3047
case(ins[`INSTRUCTION_OP])
3048
`MEMNDX:
3049
        if (ins[`INSTRUCTION_L2]==2'b00)
3050
            case(ins[`INSTRUCTION_S2])
3051
            `LBX:
3052
                case(adr[2:0])
3053
                3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3054
                3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3055
                3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3056
                3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3057
                3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3058
                3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3059
                3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3060
                3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3061
                endcase
3062
            `LBUX:
3063
                case(adr[2:0])
3064
                3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3065
                3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3066
                3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3067
                3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3068
                3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3069
                3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3070
                3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3071
                3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3072
                endcase
3073
            `LCX:
3074
                case(adr[2:1])
3075
                2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3076
                2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3077
                2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3078
                2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3079
                endcase
3080
            `LCUX:
3081
                case(adr[2:1])
3082
                2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3083
                2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3084
                2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3085
                2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3086
                endcase
3087
            `LHX:
3088
                case(adr[2])
3089
                1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3090
                1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3091
                endcase
3092
            `LHUX:
3093
                case(adr[2])
3094
                1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3095
                1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3096
                endcase
3097
            `LWX,`LWRX,`LVX,`CAS:  fnDati = dat;
3098
//          `LVx:
3099
//              case(ins[25:23])
3100
//                  `LVB:
3101
//                      case(adr[2:0])
3102
//                      3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3103
//                      3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3104
//                      3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3105
//                      3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3106
//                      3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3107
//                      3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3108
//                      3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3109
//                      3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3110
//                      endcase
3111
//                  `LVBU:
3112
//                      case(adr[2:0])
3113
//                      3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3114
//                      3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3115
//                      3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3116
//                      3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3117
//                      3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3118
//                      3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3119
//                      3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3120
//                      3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3121
//                      endcase
3122
//                  `LVC:
3123
//                      case(adr[2:1])
3124
//                      2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3125
//                      2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3126
//                      2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3127
//                      2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3128
//                      endcase
3129
//                  `LVCU:
3130
//                      case(adr[2:1])
3131
//                      2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3132
//                      2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3133
//                      2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3134
//                      2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3135
//                      endcase
3136
//                  `LVH:
3137
//                      case(adr[2])
3138
//                      1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3139
//                      1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3140
//                      endcase
3141
//                  `LVHU:
3142
//                      case(adr[2])
3143
//                      1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3144
//                      1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3145
//                      endcase
3146
//                  `LVW:  fnDati = dat;
3147
//                  default:    fnDati = dat;
3148
//              endcase
3149
            default:    fnDati = dat;
3150
            endcase
3151
        else
3152
                fnDati = dat;
3153
`LB:
3154
  case(adr[2:0])
3155
  3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3156
  3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3157
  3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3158
  3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3159
  3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3160
  3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3161
  3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3162
  3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3163
  endcase
3164
`LBU:
3165
  case(adr[2:0])
3166
  3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3167
  3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3168
  3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3169
  3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3170
  3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3171
  3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3172
  3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3173
  3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3174
  endcase
3175
`Lx:
3176
        casez(ins[20:18])
3177
        3'b100: fnDati = dat;
3178
        3'b?10:
3179
          case(adr[2])
3180
          1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3181
          1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3182
          endcase
3183
        3'b??1:
3184
          case(adr[2:1])
3185
          2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3186
          2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3187
          2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3188
          2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3189
          endcase
3190
        endcase
3191
`LxU:
3192
        casez(ins[20:18])
3193
        3'b100: fnDati = dat;
3194
        3'b?10:
3195
          case(adr[2])
3196
          1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3197
          1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3198
          endcase
3199
        3'b??1:
3200
          case(adr[2:1])
3201
          2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3202
          2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3203
          2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3204
          2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3205
          endcase
3206
        endcase
3207
`LWR,`LV,`CAS,`AMO:   fnDati = dat;
3208
//`LVx:
3209
//      case(ins[30:28])
3210
//    `LVB:
3211
//        case(adr[2:0])
3212
//        3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3213
//        3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3214
//        3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3215
//        3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3216
//        3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3217
//        3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3218
//        3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3219
//        3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3220
//        endcase
3221
//    `LVBU:
3222
//        case(adr[2:0])
3223
//        3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3224
//        3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3225
//        3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3226
//        3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3227
//        3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3228
//        3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3229
//        3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3230
//        3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3231
//        endcase
3232
//    `LVC:
3233
//        case(adr[2:1])
3234
//        2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3235
//        2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3236
//        2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3237
//        2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3238
//        endcase
3239
//    `LVCU:
3240
//        case(adr[2:1])
3241
//        2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3242
//        2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3243
//        2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3244
//        2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3245
//        endcase
3246
//    `LVH:
3247
//        case(adr[2])
3248
//        1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3249
//        1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3250
//        endcase
3251
//    `LVHU:
3252
//        case(adr[2])
3253
//        1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3254
//        1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3255
//        endcase
3256
////    `LVW:  fnDati = dat;
3257
//    default:  fnDati = dat;
3258
//      endcase
3259
default:    fnDati = dat;
3260
endcase
3261
endfunction
3262
 
3263
function [63:0] fnDato;
3264
input [47:0] isn;
3265
input [63:0] dat;
3266
case(isn[`INSTRUCTION_OP])
3267
`MEMNDX:
3268
        if (isn[`INSTRUCTION_L2]==2'b00)
3269
                case(isn[`INSTRUCTION_S2])
3270
                `SBX:   fnDato = {8{dat[7:0]}};
3271
                `SCX:   fnDato = {4{dat[15:0]}};
3272
                `SHX:   fnDato = {2{dat[31:0]}};
3273
                default:    fnDato = dat;
3274
                endcase
3275
        else
3276
                fnDato = dat;
3277
`SB:   fnDato = {8{dat[7:0]}};
3278
`Sx:
3279 49 robfinch
        casez(isn[20:18])
3280 48 robfinch
        3'b100: fnDato = dat;
3281
        3'b?10: fnDato = {2{dat[31:0]}};
3282
        3'b??1: fnDato = {4{dat[15:0]}};
3283
        default:        fnDato = dat;
3284
        endcase
3285
`AMO:
3286
        case(isn[23:21])
3287
        3'd0:   fnDato = {8{dat[7:0]}};
3288
        3'd1:   fnDato = {4{dat[15:0]}};
3289
        3'd2:   fnDato = {2{dat[31:0]}};
3290
        3'd3:   fnDato = dat;
3291
        default:        fnDato = dat;
3292
        endcase
3293
default:    fnDato = dat;
3294
endcase
3295
endfunction
3296
 
3297
// Indicate if the ALU instruction is valid immediately (single cycle operation)
3298
function IsSingleCycle;
3299
input [47:0] isn;
3300
IsSingleCycle = !(IsMul(isn)|IsDivmod(isn));
3301
endfunction
3302
 
3303
 
3304
`ifdef SUPPORT_SMT
3305
decoder8 iq0(.num({iqentry_tgt[0][8:7],iqentry_tgt[0][5:0]}), .out(iq0_out));
3306
decoder8 iq1(.num({iqentry_tgt[1][8:7],iqentry_tgt[1][5:0]}), .out(iq1_out));
3307
decoder8 iq2(.num({iqentry_tgt[2][8:7],iqentry_tgt[2][5:0]}), .out(iq2_out));
3308
decoder8 iq3(.num({iqentry_tgt[3][8:7],iqentry_tgt[3][5:0]}), .out(iq3_out));
3309
decoder8 iq4(.num({iqentry_tgt[4][8:7],iqentry_tgt[4][5:0]}), .out(iq4_out));
3310
decoder8 iq5(.num({iqentry_tgt[5][8:7],iqentry_tgt[5][5:0]}), .out(iq5_out));
3311
decoder8 iq6(.num({iqentry_tgt[6][8:7],iqentry_tgt[6][5:0]}), .out(iq6_out));
3312
decoder8 iq7(.num({iqentry_tgt[7][8:7],iqentry_tgt[7][5:0]}), .out(iq7_out));
3313
`else
3314
decoder7 iq0(.num({iqentry_tgt[0][7],iqentry_tgt[0][5:0]}), .out(iq0_out));
3315
decoder7 iq1(.num({iqentry_tgt[1][7],iqentry_tgt[1][5:0]}), .out(iq1_out));
3316
decoder7 iq2(.num({iqentry_tgt[2][7],iqentry_tgt[2][5:0]}), .out(iq2_out));
3317
decoder7 iq3(.num({iqentry_tgt[3][7],iqentry_tgt[3][5:0]}), .out(iq3_out));
3318
decoder7 iq4(.num({iqentry_tgt[4][7],iqentry_tgt[4][5:0]}), .out(iq4_out));
3319
decoder7 iq5(.num({iqentry_tgt[5][7],iqentry_tgt[5][5:0]}), .out(iq5_out));
3320
decoder7 iq6(.num({iqentry_tgt[6][7],iqentry_tgt[6][5:0]}), .out(iq6_out));
3321
decoder7 iq7(.num({iqentry_tgt[7][7],iqentry_tgt[7][5:0]}), .out(iq7_out));
3322
/*
3323
decoder6 iq0(.num({iqentry_tgt[0][5:0]}), .out(iq0_out));
3324
decoder6 iq1(.num({iqentry_tgt[1][5:0]}), .out(iq1_out));
3325
decoder6 iq2(.num({iqentry_tgt[2][5:0]}), .out(iq2_out));
3326
decoder6 iq3(.num({iqentry_tgt[3][5:0]}), .out(iq3_out));
3327
decoder6 iq4(.num({iqentry_tgt[4][5:0]}), .out(iq4_out));
3328
decoder6 iq5(.num({iqentry_tgt[5][5:0]}), .out(iq5_out));
3329
decoder6 iq6(.num({iqentry_tgt[6][5:0]}), .out(iq6_out));
3330
decoder6 iq7(.num({iqentry_tgt[7][5:0]}), .out(iq7_out));*/
3331
`endif
3332
 
3333
initial begin: Init
3334
        //
3335
        //
3336
        // set up panic messages
3337
        message[ `PANIC_NONE ]                  = "NONE            ";
3338
        message[ `PANIC_FETCHBUFBEQ ]           = "FETCHBUFBEQ     ";
3339
        message[ `PANIC_INVALIDISLOT ]          = "INVALIDISLOT    ";
3340
        message[ `PANIC_IDENTICALDRAMS ]        = "IDENTICALDRAMS  ";
3341
        message[ `PANIC_OVERRUN ]               = "OVERRUN         ";
3342
        message[ `PANIC_HALTINSTRUCTION ]       = "HALTINSTRUCTION ";
3343
        message[ `PANIC_INVALIDMEMOP ]          = "INVALIDMEMOP    ";
3344
        message[ `PANIC_INVALIDFBSTATE ]        = "INVALIDFBSTATE  ";
3345
        message[ `PANIC_INVALIDIQSTATE ]        = "INVALIDIQSTATE  ";
3346
        message[ `PANIC_BRANCHBACK ]            = "BRANCHBACK      ";
3347
        message[ `PANIC_MEMORYRACE ]            = "MEMORYRACE      ";
3348
        message[ `PANIC_ALU0ONLY ] = "ALU0 Only       ";
3349
 
3350
        for (n = 0; n < 64; n = n + 1)
3351
                codebuf[n] <= 48'h0;
3352
 
3353
end
3354
 
3355
// ---------------------------------------------------------------------------
3356
// FETCH
3357
// ---------------------------------------------------------------------------
3358
//
3359
assign fetchbuf0_mem   = IsMem(fetchbuf0_instr);
3360
assign fetchbuf0_memld = IsMem(fetchbuf0_instr) & IsLoad(fetchbuf0_instr);
3361
assign fetchbuf0_jmp   = IsFlowCtrl(fetchbuf0_instr);
3362
assign fetchbuf0_rfw   = IsRFW(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd);
3363
 
3364
assign fetchbuf1_mem   = IsMem(fetchbuf1_instr);
3365
assign fetchbuf1_memld = IsMem(fetchbuf1_instr) & IsLoad(fetchbuf1_instr);
3366
assign fetchbuf1_jmp   = IsFlowCtrl(fetchbuf1_instr);
3367
assign fetchbuf1_rfw   = IsRFW(fetchbuf1_instr,vqe1,vl,fetchbuf1_thrd);
3368
 
3369
FT64_fetchbuf #(AMSB,RSTPC) ufb1
3370
(
3371 49 robfinch
  .rst(rst),
3372
  .clk4x(clk4x),
3373
  .clk(clk),
3374
  .fcu_clk(fcu_clk),
3375
  .cs_i(adr_o[31:16]==16'hFFFF),
3376
  .cyc_i(cyc_o),
3377
  .stb_i(stb_o),
3378
  .ack_o(dc_ack),
3379
  .we_i(we_o),
3380
  .adr_i(adr_o[15:0]),
3381
  .dat_i(dat_o[31:0]),
3382
  .hirq(hirq),
3383
  .regLR(regLR),
3384
  .thread_en(thread_en),
3385
  .insn0(insn0),
3386
  .insn1(insn1),
3387
  .phit(phit),
3388
  .threadx(threadx),
3389
  .branchmiss(branchmiss),
3390
  .misspc(misspc),
3391
  .branchmiss_thrd(branchmiss_thrd),
3392
  .predict_takenA(predict_takenA),
3393
  .predict_takenB(predict_takenB),
3394
  .predict_takenC(predict_takenC),
3395
  .predict_takenD(predict_takenD),
3396
  .predict_taken0(predict_taken0),
3397
  .predict_taken1(predict_taken1),
3398
  .queued1(queued1),
3399
  .queued2(queued2),
3400
  .queuedNop(queuedNop),
3401
  .pc0(pc0),
3402
  .pc1(pc1),
3403
  .fetchbuf(fetchbuf),
3404
  .fetchbufA_v(fetchbufA_v),
3405
  .fetchbufB_v(fetchbufB_v),
3406
  .fetchbufC_v(fetchbufC_v),
3407
  .fetchbufD_v(fetchbufD_v),
3408
  .fetchbufA_pc(fetchbufA_pc),
3409
  .fetchbufB_pc(fetchbufB_pc),
3410
  .fetchbufC_pc(fetchbufC_pc),
3411
  .fetchbufD_pc(fetchbufD_pc),
3412
  .fetchbufA_instr(fetchbufA_instr),
3413
  .fetchbufB_instr(fetchbufB_instr),
3414
  .fetchbufC_instr(fetchbufC_instr),
3415
  .fetchbufD_instr(fetchbufD_instr),
3416
  .fetchbuf0_instr(fetchbuf0_instr),
3417
  .fetchbuf1_instr(fetchbuf1_instr),
3418
  .fetchbuf0_thrd(fetchbuf0_thrd),
3419
  .fetchbuf1_thrd(fetchbuf1_thrd),
3420
  .fetchbuf0_pc(fetchbuf0_pc),
3421
  .fetchbuf1_pc(fetchbuf1_pc),
3422
  .fetchbuf0_v(fetchbuf0_v),
3423
  .fetchbuf1_v(fetchbuf1_v),
3424
  .fetchbuf0_insln(fetchbuf0_insln),
3425
  .fetchbuf1_insln(fetchbuf1_insln),
3426
  .codebuf0(codebuf[insn0[21:16]]),
3427
  .codebuf1(codebuf[insn1[21:16]]),
3428
  .btgtA(btgtA),
3429
  .btgtB(btgtB),
3430
  .btgtC(btgtC),
3431
  .btgtD(btgtD),
3432
  .nop_fetchbuf(nop_fetchbuf),
3433
  .take_branch0(take_branch0),
3434
  .take_branch1(take_branch1),
3435
  .stompedRets(stompedOnRets),
3436
  .panic(fb_panic)
3437 48 robfinch
);
3438
 
3439
 
3440
 
3441
//initial begin: stop_at
3442
//#1000000; panic <= `PANIC_OVERRUN;
3443
//end
3444
 
3445
//
3446
// BRANCH-MISS LOGIC: livetarget
3447
//
3448
// livetarget implies that there is a not-to-be-stomped instruction that targets the register in question
3449
// therefore, if it is zero it implies the rf_v value should become VALID on a branchmiss
3450
// 
3451
 
3452
generate begin : live_target
3453
    for (g = 1; g < PREGS; g = g + 1) begin : lvtgt
3454
    assign livetarget[g] = iqentry_0_livetarget[g] |
3455
                        iqentry_1_livetarget[g] |
3456
                        iqentry_2_livetarget[g] |
3457
                        iqentry_3_livetarget[g] |
3458
                        iqentry_4_livetarget[g] |
3459
                        iqentry_5_livetarget[g] |
3460
                        iqentry_6_livetarget[g] |
3461
                        iqentry_7_livetarget[g];
3462
    end
3463
end
3464
endgenerate
3465
 
3466
    assign  iqentry_0_livetarget = {PREGS {iqentry_v[0]}} & {PREGS {~iqentry_stomp[0] && iqentry_thrd[0]==branchmiss_thrd}} & iq0_out,
3467
            iqentry_1_livetarget = {PREGS {iqentry_v[1]}} & {PREGS {~iqentry_stomp[1] && iqentry_thrd[1]==branchmiss_thrd}} & iq1_out,
3468
            iqentry_2_livetarget = {PREGS {iqentry_v[2]}} & {PREGS {~iqentry_stomp[2] && iqentry_thrd[2]==branchmiss_thrd}} & iq2_out,
3469
            iqentry_3_livetarget = {PREGS {iqentry_v[3]}} & {PREGS {~iqentry_stomp[3] && iqentry_thrd[3]==branchmiss_thrd}} & iq3_out,
3470
            iqentry_4_livetarget = {PREGS {iqentry_v[4]}} & {PREGS {~iqentry_stomp[4] && iqentry_thrd[4]==branchmiss_thrd}} & iq4_out,
3471
            iqentry_5_livetarget = {PREGS {iqentry_v[5]}} & {PREGS {~iqentry_stomp[5] && iqentry_thrd[5]==branchmiss_thrd}} & iq5_out,
3472
            iqentry_6_livetarget = {PREGS {iqentry_v[6]}} & {PREGS {~iqentry_stomp[6] && iqentry_thrd[6]==branchmiss_thrd}} & iq6_out,
3473
            iqentry_7_livetarget = {PREGS {iqentry_v[7]}} & {PREGS {~iqentry_stomp[7] && iqentry_thrd[7]==branchmiss_thrd}} & iq7_out;
3474
 
3475
    //
3476
    // BRANCH-MISS LOGIC: latestID
3477
    //
3478
    // latestID is the instruction queue ID of the newest instruction (latest) that targets
3479
    // a particular register.  looks a lot like scheduling logic, but in reverse.
3480
    // 
3481
    assign iqentry_0_cumulative = (missid==3'd0) ? iqentry_0_livetarget :
3482
                                  (missid==3'd1) ? iqentry_0_livetarget |
3483
                                                   iqentry_1_livetarget :
3484
                                  (missid==3'd2) ? iqentry_0_livetarget |
3485
                                                   iqentry_1_livetarget |
3486
                                                   iqentry_2_livetarget :
3487
                                  (missid==3'd3) ? iqentry_0_livetarget |
3488
                                                   iqentry_1_livetarget |
3489
                                                   iqentry_2_livetarget |
3490
                                                   iqentry_3_livetarget :
3491
                                  (missid==3'd4) ? iqentry_0_livetarget |
3492
                                                   iqentry_1_livetarget |
3493
                                                   iqentry_2_livetarget |
3494
                                                   iqentry_3_livetarget |
3495
                                                   iqentry_4_livetarget :
3496
                                  (missid==3'd5) ? iqentry_0_livetarget |
3497
                                                   iqentry_1_livetarget |
3498
                                                   iqentry_2_livetarget |
3499
                                                   iqentry_3_livetarget |
3500
                                                   iqentry_4_livetarget |
3501
                                                   iqentry_5_livetarget :
3502
                                  (missid==3'd6) ? iqentry_0_livetarget |
3503
                                                   iqentry_1_livetarget |
3504
                                                   iqentry_2_livetarget |
3505
                                                   iqentry_3_livetarget |
3506
                                                   iqentry_4_livetarget |
3507
                                                   iqentry_5_livetarget |
3508
                                                   iqentry_6_livetarget :
3509
                                  (missid==3'd7) ? iqentry_0_livetarget |
3510
                                                   iqentry_1_livetarget |
3511
                                                   iqentry_2_livetarget |
3512
                                                   iqentry_3_livetarget |
3513
                                                   iqentry_4_livetarget |
3514
                                                   iqentry_5_livetarget |
3515
                                                   iqentry_6_livetarget |
3516
                                                   iqentry_7_livetarget :
3517
                                                   {PREGS{1'b0}};
3518
 
3519
    assign iqentry_1_cumulative = (missid==3'd1) ? iqentry_1_livetarget :
3520
                                  (missid==3'd2) ? iqentry_1_livetarget |
3521
                                                   iqentry_2_livetarget :
3522
                                  (missid==3'd3) ? iqentry_1_livetarget |
3523
                                                   iqentry_2_livetarget |
3524
                                                   iqentry_3_livetarget :
3525
                                  (missid==3'd4) ? iqentry_1_livetarget |
3526
                                                   iqentry_2_livetarget |
3527
                                                   iqentry_3_livetarget |
3528
                                                   iqentry_4_livetarget :
3529
                                  (missid==3'd5) ? iqentry_1_livetarget |
3530
                                                   iqentry_2_livetarget |
3531
                                                   iqentry_3_livetarget |
3532
                                                   iqentry_4_livetarget |
3533
                                                   iqentry_5_livetarget :
3534
                                  (missid==3'd6) ? iqentry_1_livetarget |
3535
                                                   iqentry_2_livetarget |
3536
                                                   iqentry_3_livetarget |
3537
                                                   iqentry_4_livetarget |
3538
                                                   iqentry_5_livetarget |
3539
                                                   iqentry_6_livetarget :
3540
                                  (missid==3'd7) ? iqentry_1_livetarget |
3541
                                                   iqentry_2_livetarget |
3542
                                                   iqentry_3_livetarget |
3543
                                                   iqentry_4_livetarget |
3544
                                                   iqentry_5_livetarget |
3545
                                                   iqentry_6_livetarget |
3546
                                                   iqentry_7_livetarget :
3547
                                  (missid==3'd0) ? iqentry_1_livetarget |
3548
                                                   iqentry_2_livetarget |
3549
                                                   iqentry_3_livetarget |
3550
                                                   iqentry_4_livetarget |
3551
                                                   iqentry_5_livetarget |
3552
                                                   iqentry_6_livetarget |
3553
                                                   iqentry_7_livetarget |
3554
                                                   iqentry_0_livetarget :
3555
                                                   {PREGS{1'b0}};
3556
 
3557
    assign iqentry_2_cumulative = (missid==3'd2) ? iqentry_2_livetarget :
3558
                                     (missid==3'd3) ? iqentry_2_livetarget |
3559
                                                      iqentry_3_livetarget :
3560
                                     (missid==3'd4) ? iqentry_2_livetarget |
3561
                                                      iqentry_3_livetarget |
3562
                                                      iqentry_4_livetarget :
3563
                                     (missid==3'd5) ? iqentry_2_livetarget |
3564
                                                      iqentry_3_livetarget |
3565
                                                      iqentry_4_livetarget |
3566
                                                      iqentry_5_livetarget :
3567
                                     (missid==3'd6) ? iqentry_2_livetarget |
3568
                                                      iqentry_3_livetarget |
3569
                                                      iqentry_4_livetarget |
3570
                                                      iqentry_5_livetarget |
3571
                                                      iqentry_6_livetarget :
3572
                                     (missid==3'd7) ? iqentry_2_livetarget |
3573
                                                      iqentry_3_livetarget |
3574
                                                      iqentry_4_livetarget |
3575
                                                      iqentry_5_livetarget |
3576
                                                      iqentry_6_livetarget |
3577
                                                      iqentry_7_livetarget :
3578
                                     (missid==3'd0) ? iqentry_2_livetarget |
3579
                                                      iqentry_3_livetarget |
3580
                                                      iqentry_4_livetarget |
3581
                                                      iqentry_5_livetarget |
3582
                                                      iqentry_6_livetarget |
3583
                                                      iqentry_7_livetarget |
3584
                                                      iqentry_0_livetarget :
3585
                                     (missid==3'd1) ? iqentry_2_livetarget |
3586
                                                      iqentry_3_livetarget |
3587
                                                      iqentry_4_livetarget |
3588
                                                      iqentry_5_livetarget |
3589
                                                      iqentry_6_livetarget |
3590
                                                      iqentry_7_livetarget |
3591
                                                      iqentry_0_livetarget |
3592
                                                      iqentry_1_livetarget :
3593
                                                      {PREGS{1'b0}};
3594
 
3595
    assign iqentry_3_cumulative = (missid==3'd3) ? iqentry_3_livetarget :
3596
                                     (missid==3'd4) ? iqentry_3_livetarget |
3597
                                                      iqentry_4_livetarget :
3598
                                     (missid==3'd5) ? iqentry_3_livetarget |
3599
                                                      iqentry_4_livetarget |
3600
                                                      iqentry_5_livetarget :
3601
                                     (missid==3'd6) ? iqentry_3_livetarget |
3602
                                                      iqentry_4_livetarget |
3603
                                                      iqentry_5_livetarget |
3604
                                                      iqentry_6_livetarget :
3605
                                     (missid==3'd7) ? iqentry_3_livetarget |
3606
                                                      iqentry_4_livetarget |
3607
                                                      iqentry_5_livetarget |
3608
                                                      iqentry_6_livetarget |
3609
                                                      iqentry_7_livetarget :
3610
                                     (missid==3'd0) ? iqentry_3_livetarget |
3611
                                                      iqentry_4_livetarget |
3612
                                                      iqentry_5_livetarget |
3613
                                                      iqentry_6_livetarget |
3614
                                                      iqentry_7_livetarget |
3615
                                                      iqentry_0_livetarget :
3616
                                     (missid==3'd1) ? iqentry_3_livetarget |
3617
                                                      iqentry_4_livetarget |
3618
                                                      iqentry_5_livetarget |
3619
                                                      iqentry_6_livetarget |
3620
                                                      iqentry_7_livetarget |
3621
                                                      iqentry_0_livetarget |
3622
                                                      iqentry_1_livetarget :
3623
                                     (missid==3'd2) ? iqentry_3_livetarget |
3624
                                                      iqentry_4_livetarget |
3625
                                                      iqentry_5_livetarget |
3626
                                                      iqentry_6_livetarget |
3627
                                                      iqentry_7_livetarget |
3628
                                                      iqentry_0_livetarget |
3629
                                                      iqentry_1_livetarget |
3630
                                                      iqentry_2_livetarget :
3631
                                                      {PREGS{1'b0}};
3632
 
3633
    assign iqentry_4_cumulative = (missid==3'd4) ? iqentry_4_livetarget :
3634
                                     (missid==3'd5) ? iqentry_4_livetarget |
3635
                                                      iqentry_5_livetarget :
3636
                                     (missid==3'd6) ? iqentry_4_livetarget |
3637
                                                      iqentry_5_livetarget |
3638
                                                      iqentry_6_livetarget :
3639
                                     (missid==3'd7) ? iqentry_4_livetarget |
3640
                                                      iqentry_5_livetarget |
3641
                                                      iqentry_6_livetarget |
3642
                                                      iqentry_7_livetarget :
3643
                                     (missid==3'd0) ? iqentry_4_livetarget |
3644
                                                      iqentry_5_livetarget |
3645
                                                      iqentry_6_livetarget |
3646
                                                      iqentry_7_livetarget |
3647
                                                      iqentry_0_livetarget :
3648
                                     (missid==3'd1) ? iqentry_4_livetarget |
3649
                                                      iqentry_5_livetarget |
3650
                                                      iqentry_6_livetarget |
3651
                                                      iqentry_7_livetarget |
3652
                                                      iqentry_0_livetarget |
3653
                                                      iqentry_1_livetarget :
3654
                                     (missid==3'd2) ? iqentry_4_livetarget |
3655
                                                      iqentry_5_livetarget |
3656
                                                      iqentry_6_livetarget |
3657
                                                      iqentry_7_livetarget |
3658
                                                      iqentry_0_livetarget |
3659
                                                      iqentry_1_livetarget |
3660
                                                      iqentry_2_livetarget :
3661
                                     (missid==3'd3) ? iqentry_4_livetarget |
3662
                                                      iqentry_5_livetarget |
3663
                                                      iqentry_6_livetarget |
3664
                                                      iqentry_7_livetarget |
3665
                                                      iqentry_0_livetarget |
3666
                                                      iqentry_1_livetarget |
3667
                                                      iqentry_2_livetarget |
3668
                                                      iqentry_3_livetarget :
3669
                                                      {PREGS{1'b0}};
3670
 
3671
    assign iqentry_5_cumulative = (missid==3'd5) ? iqentry_5_livetarget :
3672
                                     (missid==3'd6) ? iqentry_5_livetarget |
3673
                                                      iqentry_6_livetarget :
3674
                                     (missid==3'd7) ? iqentry_5_livetarget |
3675
                                                      iqentry_6_livetarget |
3676
                                                      iqentry_7_livetarget :
3677
                                     (missid==3'd0) ? iqentry_5_livetarget |
3678
                                                      iqentry_6_livetarget |
3679
                                                      iqentry_7_livetarget |
3680
                                                      iqentry_0_livetarget :
3681
                                     (missid==3'd1) ? iqentry_5_livetarget |
3682
                                                      iqentry_6_livetarget |
3683
                                                      iqentry_7_livetarget |
3684
                                                      iqentry_0_livetarget |
3685
                                                      iqentry_1_livetarget :
3686
                                     (missid==3'd2) ? iqentry_5_livetarget |
3687
                                                      iqentry_6_livetarget |
3688
                                                      iqentry_7_livetarget |
3689
                                                      iqentry_0_livetarget |
3690
                                                      iqentry_1_livetarget |
3691
                                                      iqentry_2_livetarget :
3692
                                     (missid==3'd3) ? iqentry_5_livetarget |
3693
                                                      iqentry_6_livetarget |
3694
                                                      iqentry_7_livetarget |
3695
                                                      iqentry_0_livetarget |
3696
                                                      iqentry_1_livetarget |
3697
                                                      iqentry_2_livetarget |
3698
                                                      iqentry_3_livetarget :
3699
                                     (missid==3'd4) ? iqentry_5_livetarget |
3700
                                                      iqentry_6_livetarget |
3701
                                                      iqentry_7_livetarget |
3702
                                                      iqentry_0_livetarget |
3703
                                                      iqentry_1_livetarget |
3704
                                                      iqentry_2_livetarget |
3705
                                                      iqentry_3_livetarget |
3706
                                                      iqentry_4_livetarget :
3707
                                                      {PREGS{1'b0}};
3708
    assign iqentry_6_cumulative = (missid==3'd6) ? iqentry_6_livetarget :
3709
                                       (missid==3'd7) ? iqentry_6_livetarget |
3710
                                                        iqentry_7_livetarget :
3711
                                       (missid==3'd0) ? iqentry_6_livetarget |
3712
                                                        iqentry_7_livetarget |
3713
                                                        iqentry_0_livetarget :
3714
                                       (missid==3'd1) ? iqentry_6_livetarget |
3715
                                                        iqentry_7_livetarget |
3716
                                                        iqentry_0_livetarget |
3717
                                                        iqentry_1_livetarget :
3718
                                       (missid==3'd2) ? iqentry_6_livetarget |
3719
                                                        iqentry_7_livetarget |
3720
                                                        iqentry_0_livetarget |
3721
                                                        iqentry_1_livetarget |
3722
                                                        iqentry_2_livetarget :
3723
                                       (missid==3'd3) ? iqentry_6_livetarget |
3724
                                                        iqentry_7_livetarget |
3725
                                                        iqentry_0_livetarget |
3726
                                                        iqentry_1_livetarget |
3727
                                                        iqentry_2_livetarget |
3728
                                                        iqentry_3_livetarget :
3729
                                       (missid==3'd4) ? iqentry_6_livetarget |
3730
                                                        iqentry_7_livetarget |
3731
                                                        iqentry_0_livetarget |
3732
                                                        iqentry_1_livetarget |
3733
                                                        iqentry_2_livetarget |
3734
                                                        iqentry_3_livetarget |
3735
                                                        iqentry_4_livetarget :
3736
                                       (missid==3'd5) ? iqentry_6_livetarget |
3737
                                                        iqentry_7_livetarget |
3738
                                                        iqentry_0_livetarget |
3739
                                                        iqentry_1_livetarget |
3740
                                                        iqentry_2_livetarget |
3741
                                                        iqentry_3_livetarget |
3742
                                                        iqentry_4_livetarget |
3743
                                                        iqentry_5_livetarget :
3744
                                                        {PREGS{1'b0}};
3745
 
3746
    assign iqentry_7_cumulative = (missid==3'd7) ? iqentry_7_livetarget :
3747
                                       (missid==3'd0) ? iqentry_7_livetarget |
3748
                                                        iqentry_0_livetarget :
3749
                                       (missid==3'd1) ? iqentry_7_livetarget |
3750
                                                        iqentry_0_livetarget |
3751
                                                        iqentry_1_livetarget :
3752
                                       (missid==3'd2) ? iqentry_7_livetarget |
3753
                                                        iqentry_0_livetarget |
3754
                                                        iqentry_1_livetarget |
3755
                                                        iqentry_2_livetarget :
3756
                                       (missid==3'd3) ? iqentry_7_livetarget |
3757
                                                        iqentry_0_livetarget |
3758
                                                        iqentry_1_livetarget |
3759
                                                        iqentry_2_livetarget |
3760
                                                        iqentry_3_livetarget :
3761
                                       (missid==3'd4) ? iqentry_7_livetarget |
3762
                                                        iqentry_0_livetarget |
3763
                                                        iqentry_1_livetarget |
3764
                                                        iqentry_2_livetarget |
3765
                                                        iqentry_3_livetarget |
3766
                                                        iqentry_4_livetarget :
3767
                                       (missid==3'd5) ? iqentry_7_livetarget |
3768
                                                        iqentry_0_livetarget |
3769
                                                        iqentry_1_livetarget |
3770
                                                        iqentry_2_livetarget |
3771
                                                        iqentry_3_livetarget |
3772
                                                        iqentry_4_livetarget |
3773
                                                        iqentry_5_livetarget :
3774
                                       (missid==3'd6) ? iqentry_7_livetarget |
3775
                                                        iqentry_0_livetarget |
3776
                                                        iqentry_1_livetarget |
3777
                                                        iqentry_2_livetarget |
3778
                                                        iqentry_3_livetarget |
3779
                                                        iqentry_4_livetarget |
3780
                                                        iqentry_5_livetarget |
3781
                                                        iqentry_6_livetarget :
3782
                                                        {PREGS{1'b0}};
3783
 
3784
    assign iqentry_0_latestID = (missid == 3'd0 || ((iqentry_0_livetarget & iqentry_1_cumulative) == {PREGS{1'b0}}))
3785
                                    ? iqentry_0_livetarget
3786
                                    : {PREGS{1'b0}};
3787
 
3788
    assign iqentry_1_latestID = (missid == 3'd1 || ((iqentry_1_livetarget & iqentry_2_cumulative) == {PREGS{1'b0}}))
3789
                                    ? iqentry_1_livetarget
3790
                                    : {PREGS{1'b0}};
3791
 
3792
    assign iqentry_2_latestID = (missid == 3'd2 || ((iqentry_2_livetarget & iqentry_3_cumulative) == {PREGS{1'b0}}))
3793
                                    ? iqentry_2_livetarget
3794
                                    : {PREGS{1'b0}};
3795
 
3796
    assign iqentry_3_latestID = (missid == 3'd3 || ((iqentry_3_livetarget & iqentry_4_cumulative) == {PREGS{1'b0}}))
3797
                                    ? iqentry_3_livetarget
3798
                                    : {PREGS{1'b0}};
3799
 
3800
    assign iqentry_4_latestID = (missid == 3'd4 || ((iqentry_4_livetarget & iqentry_5_cumulative) == {PREGS{1'b0}}))
3801
                                    ? iqentry_4_livetarget
3802
                                    : {PREGS{1'b0}};
3803
 
3804
    assign iqentry_5_latestID = (missid == 3'd5 || ((iqentry_5_livetarget & iqentry_6_cumulative) == {PREGS{1'b0}}))
3805
                                    ? iqentry_5_livetarget
3806
                                    : {PREGS{1'b0}};
3807
 
3808
    assign iqentry_6_latestID = (missid == 3'd6 || ((iqentry_6_livetarget & iqentry_7_cumulative) == {PREGS{1'b0}}))
3809
                                    ? iqentry_6_livetarget
3810
                                    : {PREGS{1'b0}};
3811
 
3812
    assign iqentry_7_latestID = (missid == 3'd7 || ((iqentry_7_livetarget & iqentry_0_cumulative) == {PREGS{1'b0}}))
3813
                                    ? iqentry_7_livetarget
3814
                                    : {PREGS{1'b0}};
3815
 
3816 49 robfinch
assign  iqentry_source[0] = | iqentry_0_latestID,
3817
  iqentry_source[1] = | iqentry_1_latestID,
3818
  iqentry_source[2] = | iqentry_2_latestID,
3819
  iqentry_source[3] = | iqentry_3_latestID,
3820
  iqentry_source[4] = | iqentry_4_latestID,
3821
  iqentry_source[5] = | iqentry_5_latestID,
3822
  iqentry_source[6] = | iqentry_6_latestID,
3823
  iqentry_source[7] = | iqentry_7_latestID;
3824 48 robfinch
 
3825
 
3826
reg vqueued2;
3827
assign Ra0 = fnRa(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3828
assign Rb0 = fnRb(fetchbuf0_instr,1'b0,vqe0,rfoa0[5:0],rfoa1[5:0],fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3829
assign Rc0 = fnRc(fetchbuf0_instr,vqe0,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3830
assign Rt0 = fnRt(fetchbuf0_instr,vqet0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3831
assign Ra1 = fnRa(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3832
assign Rb1 = fnRb(fetchbuf1_instr,1'b1,vqueued2 ? vqe0 + 1 : vqe1,rfoa0[5:0],rfoa1[5:0],fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3833
assign Rc1 = fnRc(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3834
assign Rt1 = fnRt(fetchbuf1_instr,vqueued2 ? vqet0 + 1 : vqet1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3835
 
3836 49 robfinch
//
3837
// additional logic for ISSUE
3838
//
3839
// for the moment, we look at ALU-input buffers to allow back-to-back issue of 
3840
// dependent instructions ... we do not, however, look ahead for DRAM requests 
3841
// that will become valid in the next cycle.  instead, these have to propagate
3842
// their results into the IQ entry directly, at which point it becomes issue-able
3843
//
3844 48 robfinch
 
3845 49 robfinch
// note that, for all intents & purposes, iqentry_done == iqentry_agen ... no need to duplicate
3846 48 robfinch
 
3847
wire [QENTRIES-1:0] args_valid;
3848
wire [QENTRIES-1:0] could_issue;
3849
wire [QENTRIES-1:0] could_issueid;
3850
 
3851
generate begin : issue_logic
3852
for (g = 0; g < QENTRIES; g = g + 1)
3853
begin
3854
assign args_valid[g] =
3855
                  (iqentry_a1_v[g]
3856 49 robfinch
`ifdef FU_BYPASS
3857 48 robfinch
        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
3858 49 robfinch
        || ((iqentry_a1_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3859
        || ((iqentry_a1_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
3860
`endif
3861
        )
3862 48 robfinch
    && (iqentry_a2_v[g]
3863
        || (iqentry_mem[g] & ~iqentry_agen[g] & ~iqentry_memndx[g])    // a2 needs to be valid for indexed instruction
3864 49 robfinch
`ifdef FU_BYPASS
3865 48 robfinch
        || (iqentry_a2_s[g] == alu0_sourceid && alu0_dataready)
3866 49 robfinch
        || ((iqentry_a2_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3867
        || ((iqentry_a2_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
3868
`endif
3869
        )
3870 48 robfinch
    && (iqentry_a3_v[g]
3871
//        || (iqentry_mem[g] & ~iqentry_agen[g])
3872 49 robfinch
`ifdef FU_BYPASS
3873 48 robfinch
        || (iqentry_a3_s[g] == alu0_sourceid && alu0_dataready)
3874 49 robfinch
        || ((iqentry_a3_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3875
`endif
3876
        )
3877 48 robfinch
    ;
3878
 
3879
assign could_issue[g] = iqentry_v[g] && !iqentry_done[g] && !iqentry_out[g]
3880
                                                                                                && args_valid[g]
3881
                                                                                                && iqentry_iv[g]
3882
                        && (iqentry_mem[g] ? !iqentry_agen[g] : 1'b1);
3883
 
3884
assign could_issueid[g] = iqentry_v[g] && !iqentry_iv[g];
3885
//                && (iqentry_a1_v[g] 
3886
//        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
3887
//        || (iqentry_a1_s[g] == alu1_sourceid && alu1_dataready));
3888
 
3889
end
3890
end
3891
endgenerate
3892
 
3893
// The (old) simulator didn't handle the asynchronous race loop properly in the 
3894
// original code. It would issue two instructions to the same islot. So the
3895
// issue logic has been re-written to eliminate the asynchronous loop.
3896
// Can't issue to the ALU if it's busy doing a long running operation like a 
3897
// divide.
3898
// ToDo: fix the memory synchronization, see fp_issue below
3899
 
3900
wire [`QBITS] heads [QENTRIES-1:0];
3901
assign heads[0] = head0;
3902
assign heads[1] = head1;
3903
assign heads[2] = head2;
3904
assign heads[3] = head3;
3905
assign heads[4] = head4;
3906
assign heads[5] = head5;
3907
assign heads[6] = head6;
3908
assign heads[7] = head7;
3909
 
3910
always @*
3911
begin
3912 49 robfinch
        iqentry_id1issue = {QENTRIES{1'b0}};
3913 48 robfinch
        if (id1_available) begin
3914
                for (n = 0; n < QENTRIES; n = n + 1)
3915 49 robfinch
                        if (could_issueid[heads[n]] && iqentry_id1issue=={QENTRIES{1'b0}})
3916 48 robfinch
                          iqentry_id1issue[heads[n]] = `TRUE;
3917
        end
3918 49 robfinch
end
3919
generate begin : gIDUIssue
3920
        if (`NUM_IDU > 1) begin
3921
                always @*
3922
                begin
3923
                        iqentry_id2issue = {QENTRIES{1'b0}};
3924
                        if (id2_available) begin
3925
                                for (n = 0; n < QENTRIES; n = n + 1)
3926
                                        if (could_issueid[heads[n]] && !iqentry_id1issue[heads[n]] && iqentry_id2issue=={QENTRIES{1'b0}})
3927
                                          iqentry_id2issue[heads[n]] = `TRUE;
3928
                        end
3929
                end
3930 48 robfinch
        end
3931 49 robfinch
        if (`NUM_IDU > 2) begin
3932
                always @*
3933
                begin
3934
                        iqentry_id3issue = {QENTRIES{1'b0}};
3935
                        if (id3_available) begin
3936
                                for (n = 0; n < QENTRIES; n = n + 1)
3937
                                        if (could_issueid[heads[n]]
3938
                                        && !iqentry_id1issue[heads[n]]
3939
                                        && !iqentry_id2issue[heads[n]]
3940
                                        && iqentry_id3issue=={QENTRIES{1'b0}})
3941
                                          iqentry_id3issue[heads[n]] = `TRUE;
3942
                        end
3943
                end
3944
        end
3945 48 robfinch
end
3946 49 robfinch
endgenerate
3947 48 robfinch
 
3948
always @*
3949
begin
3950 49 robfinch
        iqentry_alu0_issue = {QENTRIES{1'b0}};
3951
        iqentry_alu1_issue = {QENTRIES{1'b0}};
3952 48 robfinch
 
3953
        if (alu0_available & alu0_idle) begin
3954
                if (could_issue[head0] && iqentry_alu[head0]) begin
3955
                  iqentry_alu0_issue[head0] = `TRUE;
3956
                end
3957
                else if (could_issue[head1] && iqentry_alu[head1])
3958
                begin
3959
                  iqentry_alu0_issue[head1] = `TRUE;
3960
                end
3961
                else if (could_issue[head2] && iqentry_alu[head2]
3962
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3963
                )
3964
                begin
3965
                        iqentry_alu0_issue[head2] = `TRUE;
3966
                end
3967
                else if (could_issue[head3] && iqentry_alu[head3]
3968
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3969
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3970
                                ((!iqentry_v[head0])
3971
                        &&   (!iqentry_v[head1]))
3972
                        )
3973
                ) begin
3974
                        iqentry_alu0_issue[head3] = `TRUE;
3975
                end
3976
                else if (could_issue[head4] && iqentry_alu[head4]
3977
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3978
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3979
                                ((!iqentry_v[head0])
3980
                        &&   (!iqentry_v[head1]))
3981
                        )
3982
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3983
                                ((!iqentry_v[head0])
3984
                        &&   (!iqentry_v[head1])
3985
                        &&   (!iqentry_v[head2]))
3986
                        )
3987
                ) begin
3988
                        iqentry_alu0_issue[head4] = `TRUE;
3989
                end
3990
                else if (could_issue[head5] && iqentry_alu[head5]
3991
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3992
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3993
                                ((!iqentry_v[head0])
3994
                        &&   (!iqentry_v[head1]))
3995
                        )
3996
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3997
                                ((!iqentry_v[head0])
3998
                        &&   (!iqentry_v[head1])
3999
                        &&   (!iqentry_v[head2]))
4000
                        )
4001
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4002
                                ((!iqentry_v[head0])
4003
                        &&   (!iqentry_v[head1])
4004
                        &&   (!iqentry_v[head2])
4005
                        &&   (!iqentry_v[head3]))
4006
                        )
4007
                ) begin
4008
                        iqentry_alu0_issue[head5] = `TRUE;
4009
                end
4010
`ifdef FULL_ISSUE_LOGIC
4011
                else if (could_issue[head6] && iqentry_alu[head6]
4012
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4013
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4014
                                ((!iqentry_v[head0])
4015
                        &&   (!iqentry_v[head1]))
4016
                        )
4017
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4018
                                ((!iqentry_v[head0])
4019
                        &&   (!iqentry_v[head1])
4020
                        &&   (!iqentry_v[head2]))
4021
                        )
4022
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4023
                                ((!iqentry_v[head0])
4024
                        &&   (!iqentry_v[head1])
4025
                        &&   (!iqentry_v[head2])
4026
                        &&   (!iqentry_v[head3]))
4027
                        )
4028
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4029
                                ((!iqentry_v[head0])
4030
                        &&   (!iqentry_v[head1])
4031
                        &&   (!iqentry_v[head2])
4032
                        &&   (!iqentry_v[head3])
4033
                        &&   (!iqentry_v[head4]))
4034
                        )
4035
                ) begin
4036
                        iqentry_alu0_issue[head6] = `TRUE;
4037
                end
4038
                else if (could_issue[head7] && iqentry_alu[head7]
4039
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4040
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4041
                                ((!iqentry_v[head0])
4042
                        &&   (!iqentry_v[head1]))
4043
                        )
4044
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4045
                                ((!iqentry_v[head0])
4046
                        &&   (!iqentry_v[head1])
4047
                        &&   (!iqentry_v[head2]))
4048
                        )
4049
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4050
                                ((!iqentry_v[head0])
4051
                        &&   (!iqentry_v[head1])
4052
                        &&   (!iqentry_v[head2])
4053
                        &&   (!iqentry_v[head3]))
4054
                        )
4055
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4056
                                ((!iqentry_v[head0])
4057
                        &&   (!iqentry_v[head1])
4058
                        &&   (!iqentry_v[head2])
4059
                        &&   (!iqentry_v[head3])
4060
                        &&   (!iqentry_v[head4]))
4061
                        )
4062
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
4063
                                ((!iqentry_v[head0])
4064
                        &&   (!iqentry_v[head1])
4065
                        &&   (!iqentry_v[head2])
4066
                        &&   (!iqentry_v[head3])
4067
                        &&   (!iqentry_v[head4])
4068
                        &&   (!iqentry_v[head5]))
4069
                        )
4070
                ) begin
4071
                        iqentry_alu0_issue[head7] = `TRUE;
4072
                end
4073
`endif
4074
        end
4075
 
4076 49 robfinch
        if (alu1_available && alu1_idle && `NUM_ALU > 1) begin
4077 48 robfinch
                if ((could_issue & ~iqentry_alu0_issue & ~iqentry_alu0) != 8'h00) begin
4078
                if (could_issue[head0] && iqentry_alu[head0]
4079
                && !iqentry_alu0[head0] // alu0only
4080
                && !iqentry_alu0_issue[head0]) begin
4081
                  iqentry_alu1_issue[head0] = `TRUE;
4082
                end
4083
                else if (could_issue[head1] && !iqentry_alu0_issue[head1] && iqentry_alu[head1]
4084
                && !iqentry_alu0[head1])
4085
                begin
4086
                  iqentry_alu1_issue[head1] = `TRUE;
4087
                end
4088
                else if (could_issue[head2] && !iqentry_alu0_issue[head2] && iqentry_alu[head2]
4089
                && !iqentry_alu0[head2]
4090
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4091
                )
4092
                begin
4093
                        iqentry_alu1_issue[head2] = `TRUE;
4094
                end
4095
                else if (could_issue[head3] && !iqentry_alu0_issue[head3] && iqentry_alu[head3]
4096
                && !iqentry_alu0[head3]
4097
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4098
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4099
                                ((!iqentry_v[head0])
4100
                        &&   (!iqentry_v[head1]))
4101
                        )
4102
                ) begin
4103
                        iqentry_alu1_issue[head3] = `TRUE;
4104
                end
4105
                else if (could_issue[head4] && !iqentry_alu0_issue[head4] && iqentry_alu[head4]
4106
                && !iqentry_alu0[head4]
4107
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4108
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4109
                                ((!iqentry_v[head0])
4110
                        &&   (!iqentry_v[head1]))
4111
                        )
4112
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4113
                                ((!iqentry_v[head0])
4114
                        &&   (!iqentry_v[head1])
4115
                        &&   (!iqentry_v[head2]))
4116
                        )
4117
                ) begin
4118
                        iqentry_alu1_issue[head4] = `TRUE;
4119
                end
4120
                else if (could_issue[head5] && !iqentry_alu0_issue[head5] && iqentry_alu[head5]
4121
                && !iqentry_alu0[head5]
4122
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4123
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4124
                                ((!iqentry_v[head0])
4125
                        &&   (!iqentry_v[head1]))
4126
                        )
4127
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4128
                                ((!iqentry_v[head0])
4129
                        &&   (!iqentry_v[head1])
4130
                        &&   (!iqentry_v[head2]))
4131
                        )
4132
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4133
                                ((!iqentry_v[head0])
4134
                        &&   (!iqentry_v[head1])
4135
                        &&   (!iqentry_v[head2])
4136
                        &&   (!iqentry_v[head3]))
4137
                        )
4138
                ) begin
4139
                        iqentry_alu1_issue[head5] = `TRUE;
4140
                end
4141
`ifdef FULL_ISSUE_LOGIC
4142
                else if (could_issue[head6] && !iqentry_alu0_issue[head6] && iqentry_alu[head6]
4143
                && !iqentry_alu0[head6]
4144
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4145
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4146
                                ((!iqentry_v[head0])
4147
                        &&   (!iqentry_v[head1]))
4148
                        )
4149
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4150
                                ((!iqentry_v[head0])
4151
                        &&   (!iqentry_v[head1])
4152
                        &&   (!iqentry_v[head2]))
4153
                        )
4154
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4155
                                ((!iqentry_v[head0])
4156
                        &&   (!iqentry_v[head1])
4157
                        &&   (!iqentry_v[head2])
4158
                        &&   (!iqentry_v[head3]))
4159
                        )
4160
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4161
                                ((!iqentry_v[head0])
4162
                        &&   (!iqentry_v[head1])
4163
                        &&   (!iqentry_v[head2])
4164
                        &&   (!iqentry_v[head3])
4165
                        &&   (!iqentry_v[head4]))
4166
                        )
4167
                ) begin
4168
                        iqentry_alu1_issue[head6] = `TRUE;
4169
                end
4170
                else if (could_issue[head7] && !iqentry_alu0_issue[head7] && iqentry_alu[head7]
4171
                && !iqentry_alu0[head7]
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
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4178
                                ((!iqentry_v[head0])
4179
                        &&   (!iqentry_v[head1])
4180
                        &&   (!iqentry_v[head2]))
4181
                        )
4182
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4183
                                ((!iqentry_v[head0])
4184
                        &&   (!iqentry_v[head1])
4185
                        &&   (!iqentry_v[head2])
4186
                        &&   (!iqentry_v[head3]))
4187
                        )
4188
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4189
                                ((!iqentry_v[head0])
4190
                        &&   (!iqentry_v[head1])
4191
                        &&   (!iqentry_v[head2])
4192
                        &&   (!iqentry_v[head3])
4193
                        &&   (!iqentry_v[head4]))
4194
                        )
4195
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
4196
                                ((!iqentry_v[head0])
4197
                        &&   (!iqentry_v[head1])
4198
                        &&   (!iqentry_v[head2])
4199
                        &&   (!iqentry_v[head3])
4200
                        &&   (!iqentry_v[head4])
4201
                        &&   (!iqentry_v[head5]))
4202
                        )
4203
                ) begin
4204
                        iqentry_alu1_issue[head7] = `TRUE;
4205
                end
4206
`endif
4207
        end
4208
//      aluissue(alu0_idle,8'h00,2'b00);
4209
//      aluissue(alu1_idle,iqentry_alu0,2'b01);
4210
        end
4211
end
4212
 
4213
always @*
4214
begin
4215 49 robfinch
        iqentry_fpu1_issue = {QENTRIES{1'b0}};
4216
//      fpu1issue(fpu1_idle,2'b00);
4217
        if (fpu1_idle && `NUM_FPU > 0) begin
4218 48 robfinch
    if (could_issue[head0] && iqentry_fpu[head0]) begin
4219 49 robfinch
      iqentry_fpu1_issue[head0] = `TRUE;
4220 48 robfinch
    end
4221
    else if (could_issue[head1] && iqentry_fpu[head1])
4222
    begin
4223 49 robfinch
      iqentry_fpu1_issue[head1] = `TRUE;
4224 48 robfinch
    end
4225
    else if (could_issue[head2] && iqentry_fpu[head2]
4226
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4227
    ) begin
4228 49 robfinch
      iqentry_fpu1_issue[head2] = `TRUE;
4229 48 robfinch
    end
4230
    else if (could_issue[head3] && iqentry_fpu[head3]
4231
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4232
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4233
                ((!iqentry_v[head0])
4234
        &&   (!iqentry_v[head1]))
4235
        )
4236
    ) begin
4237 49 robfinch
      iqentry_fpu1_issue[head3] = `TRUE;
4238 48 robfinch
    end
4239
    else if (could_issue[head4] && iqentry_fpu[head4]
4240
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4241
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4242
                ((!iqentry_v[head0])
4243
        &&   (!iqentry_v[head1]))
4244
        )
4245
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4246
                ((!iqentry_v[head0])
4247
        &&   (!iqentry_v[head1])
4248
        &&   (!iqentry_v[head2]))
4249
        )
4250
    ) begin
4251 49 robfinch
      iqentry_fpu1_issue[head4] = `TRUE;
4252 48 robfinch
    end
4253
    else if (could_issue[head5] && iqentry_fpu[head5]
4254
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4255
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4256
                ((!iqentry_v[head0])
4257
        &&   (!iqentry_v[head1]))
4258
        )
4259
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4260
                ((!iqentry_v[head0])
4261
        &&   (!iqentry_v[head1])
4262
        &&   (!iqentry_v[head2]))
4263
        )
4264
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4265
                ((!iqentry_v[head0])
4266
        &&   (!iqentry_v[head1])
4267
        &&   (!iqentry_v[head2])
4268
        &&   (!iqentry_v[head3]))
4269
        )
4270
        ) begin
4271 49 robfinch
              iqentry_fpu1_issue[head5] = `TRUE;
4272 48 robfinch
    end
4273
`ifdef FULL_ISSUE_LOGIC
4274
    else if (could_issue[head6] && iqentry_fpu[head6]
4275
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4276
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4277
                ((!iqentry_v[head0])
4278
        &&   (!iqentry_v[head1]))
4279
        )
4280
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4281
                ((!iqentry_v[head0])
4282
        &&   (!iqentry_v[head1])
4283
        &&   (!iqentry_v[head2]))
4284
        )
4285
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4286
                ((!iqentry_v[head0])
4287
        &&   (!iqentry_v[head1])
4288
        &&   (!iqentry_v[head2])
4289
        &&   (!iqentry_v[head3]))
4290
        )
4291
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4292
                ((!iqentry_v[head0])
4293
        &&   (!iqentry_v[head1])
4294
        &&   (!iqentry_v[head2])
4295
        &&   (!iqentry_v[head3])
4296
        &&   (!iqentry_v[head4]))
4297
        )
4298
    ) begin
4299 49 robfinch
        iqentry_fpu1_issue[head6] = `TRUE;
4300 48 robfinch
    end
4301
    else if (could_issue[head7] && iqentry_fpu[head7]
4302
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4303
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4304
                ((!iqentry_v[head0])
4305
        &&   (!iqentry_v[head1]))
4306
        )
4307
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4308
                ((!iqentry_v[head0])
4309
        &&   (!iqentry_v[head1])
4310
        &&   (!iqentry_v[head2]))
4311
        )
4312
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4313
                ((!iqentry_v[head0])
4314
        &&   (!iqentry_v[head1])
4315
        &&   (!iqentry_v[head2])
4316
        &&   (!iqentry_v[head3]))
4317
        )
4318
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4319
                ((!iqentry_v[head0])
4320
        &&   (!iqentry_v[head1])
4321
        &&   (!iqentry_v[head2])
4322
        &&   (!iqentry_v[head3])
4323
        &&   (!iqentry_v[head4]))
4324
        )
4325
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
4326
                ((!iqentry_v[head0])
4327
        &&   (!iqentry_v[head1])
4328
        &&   (!iqentry_v[head2])
4329
        &&   (!iqentry_v[head3])
4330
        &&   (!iqentry_v[head4])
4331
        &&   (!iqentry_v[head5]))
4332
        )
4333
        )
4334
    begin
4335 49 robfinch
                iqentry_fpu1_issue[head7] = `TRUE;
4336 48 robfinch
        end
4337
`endif
4338
        end
4339
end
4340
 
4341 49 robfinch
always @*
4342
begin
4343
        iqentry_fpu2_issue = {QENTRIES{1'b0}};
4344
//      fpu2issue(fpu2_idle,2'b00);
4345
        if (fpu2_idle && `NUM_FPU > 1) begin
4346
    if (could_issue[head0] && iqentry_fpu[head0] && !iqentry_fpu1_issue[head0]) begin
4347
      iqentry_fpu2_issue[head0] = `TRUE;
4348
    end
4349
    else if (could_issue[head1] && iqentry_fpu[head1] && !iqentry_fpu1_issue[head1])
4350
    begin
4351
      iqentry_fpu2_issue[head1] = `TRUE;
4352
    end
4353
    else if (could_issue[head2] && iqentry_fpu[head2] && !iqentry_fpu1_issue[head2]
4354
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4355
    ) begin
4356
      iqentry_fpu2_issue[head2] = `TRUE;
4357
    end
4358
    else if (could_issue[head3] && iqentry_fpu[head3] && !iqentry_fpu1_issue[head3]
4359
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4360
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4361
                ((!iqentry_v[head0])
4362
        &&   (!iqentry_v[head1]))
4363
        )
4364
    ) begin
4365
      iqentry_fpu2_issue[head3] = `TRUE;
4366
    end
4367
    else if (could_issue[head4] && iqentry_fpu[head4] && !iqentry_fpu1_issue[head4]
4368
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4369
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4370
                ((!iqentry_v[head0])
4371
        &&   (!iqentry_v[head1]))
4372
        )
4373
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4374
                ((!iqentry_v[head0])
4375
        &&   (!iqentry_v[head1])
4376
        &&   (!iqentry_v[head2]))
4377
        )
4378
    ) begin
4379
      iqentry_fpu2_issue[head4] = `TRUE;
4380
    end
4381
    else if (could_issue[head5] && iqentry_fpu[head5] && !iqentry_fpu1_issue[head5]
4382
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4383
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4384
                ((!iqentry_v[head0])
4385
        &&   (!iqentry_v[head1]))
4386
        )
4387
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4388
                ((!iqentry_v[head0])
4389
        &&   (!iqentry_v[head1])
4390
        &&   (!iqentry_v[head2]))
4391
        )
4392
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4393
                ((!iqentry_v[head0])
4394
        &&   (!iqentry_v[head1])
4395
        &&   (!iqentry_v[head2])
4396
        &&   (!iqentry_v[head3]))
4397
        )
4398
        ) begin
4399
              iqentry_fpu2_issue[head5] = `TRUE;
4400
    end
4401
`ifdef FULL_ISSUE_LOGIC
4402
    else if (could_issue[head6] && iqentry_fpu[head6] && !iqentry_fpu1_issue[head6]
4403
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4404
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4405
                ((!iqentry_v[head0])
4406
        &&   (!iqentry_v[head1]))
4407
        )
4408
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4409
                ((!iqentry_v[head0])
4410
        &&   (!iqentry_v[head1])
4411
        &&   (!iqentry_v[head2]))
4412
        )
4413
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4414
                ((!iqentry_v[head0])
4415
        &&   (!iqentry_v[head1])
4416
        &&   (!iqentry_v[head2])
4417
        &&   (!iqentry_v[head3]))
4418
        )
4419
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4420
                ((!iqentry_v[head0])
4421
        &&   (!iqentry_v[head1])
4422
        &&   (!iqentry_v[head2])
4423
        &&   (!iqentry_v[head3])
4424
        &&   (!iqentry_v[head4]))
4425
        )
4426
    ) begin
4427
        iqentry_fpu2_issue[head6] = `TRUE;
4428
    end
4429
    else if (could_issue[head7] && iqentry_fpu[head7] && !iqentry_fpu1_issue[head7]
4430
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4431
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4432
                ((!iqentry_v[head0])
4433
        &&   (!iqentry_v[head1]))
4434
        )
4435
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4436
                ((!iqentry_v[head0])
4437
        &&   (!iqentry_v[head1])
4438
        &&   (!iqentry_v[head2]))
4439
        )
4440
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4441
                ((!iqentry_v[head0])
4442
        &&   (!iqentry_v[head1])
4443
        &&   (!iqentry_v[head2])
4444
        &&   (!iqentry_v[head3]))
4445
        )
4446
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4447
                ((!iqentry_v[head0])
4448
        &&   (!iqentry_v[head1])
4449
        &&   (!iqentry_v[head2])
4450
        &&   (!iqentry_v[head3])
4451
        &&   (!iqentry_v[head4]))
4452
        )
4453
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
4454
                ((!iqentry_v[head0])
4455
        &&   (!iqentry_v[head1])
4456
        &&   (!iqentry_v[head2])
4457
        &&   (!iqentry_v[head3])
4458
        &&   (!iqentry_v[head4])
4459
        &&   (!iqentry_v[head5]))
4460
        )
4461
        )
4462
    begin
4463
                iqentry_fpu2_issue[head7] = `TRUE;
4464
        end
4465
`endif
4466
        end
4467
end
4468 48 robfinch
 
4469
wire [QENTRIES-1:0] nextqd;
4470
// Next queue id
4471
 
4472
reg [`QBITS] nid0;
4473
always @*
4474
if (iqentry_thrd[1]==iqentry_thrd[0])
4475
        nid0 = 3'd1;
4476
else if (iqentry_thrd[2]==iqentry_thrd[0])
4477
        nid0 = 3'd2;
4478
else if (iqentry_thrd[3]==iqentry_thrd[0])
4479
        nid0 = 3'd3;
4480
else if (iqentry_thrd[4]==iqentry_thrd[0])
4481
        nid0 = 3'd4;
4482
else if (iqentry_thrd[5]==iqentry_thrd[0])
4483
        nid0 = 3'd5;
4484
else if (iqentry_thrd[6]==iqentry_thrd[0])
4485
        nid0 = 3'd6;
4486
else if (iqentry_thrd[7]==iqentry_thrd[0])
4487
        nid0 = 3'd7;
4488
else
4489
        nid0 = 3'd0;
4490
 
4491
reg [`QBITS] nid1;
4492
always @*
4493
if (iqentry_thrd[2]==iqentry_thrd[1])
4494
        nid1 = 3'd2;
4495
else if (iqentry_thrd[3]==iqentry_thrd[1])
4496
        nid1 = 3'd3;
4497
else if (iqentry_thrd[4]==iqentry_thrd[1])
4498
        nid1 = 3'd4;
4499
else if (iqentry_thrd[5]==iqentry_thrd[1])
4500
        nid1 = 3'd5;
4501
else if (iqentry_thrd[6]==iqentry_thrd[1])
4502
        nid1 = 3'd6;
4503
else if (iqentry_thrd[7]==iqentry_thrd[1])
4504
        nid1 = 3'd7;
4505
else if (iqentry_thrd[0]==iqentry_thrd[1])
4506
        nid1 = 3'd0;
4507
else
4508
        nid1 = 3'd1;
4509
 
4510
reg [`QBITS] nid2;
4511
always @*
4512
if (iqentry_thrd[3]==iqentry_thrd[2])
4513
        nid2 = 3'd3;
4514
else if (iqentry_thrd[4]==iqentry_thrd[2])
4515
        nid2 = 3'd4;
4516
else if (iqentry_thrd[5]==iqentry_thrd[2])
4517
        nid2 = 3'd5;
4518
else if (iqentry_thrd[6]==iqentry_thrd[2])
4519
        nid2 = 3'd6;
4520
else if (iqentry_thrd[7]==iqentry_thrd[2])
4521
        nid2 = 3'd7;
4522
else if (iqentry_thrd[0]==iqentry_thrd[2])
4523
        nid2 = 3'd0;
4524
else if (iqentry_thrd[1]==iqentry_thrd[2])
4525
        nid2 = 3'd1;
4526
else
4527
        nid2 = 3'd2;
4528
 
4529
reg [`QBITS] nid3;
4530
always @*
4531
if (iqentry_thrd[4]==iqentry_thrd[3])
4532
        nid3 = 3'd4;
4533
else if (iqentry_thrd[5]==iqentry_thrd[3])
4534
        nid3 = 3'd5;
4535
else if (iqentry_thrd[6]==iqentry_thrd[3])
4536
        nid3 = 3'd6;
4537
else if (iqentry_thrd[7]==iqentry_thrd[3])
4538
        nid3 = 3'd7;
4539
else if (iqentry_thrd[0]==iqentry_thrd[3])
4540
        nid3 = 3'd0;
4541
else if (iqentry_thrd[1]==iqentry_thrd[3])
4542
        nid3 = 3'd1;
4543
else if (iqentry_thrd[2]==iqentry_thrd[3])
4544
        nid3 = 3'd2;
4545
else
4546
        nid3 = 3'd3;
4547
 
4548
reg [`QBITS] nid4;
4549
always @*
4550
if (iqentry_thrd[5]==iqentry_thrd[4])
4551
        nid4 = 3'd5;
4552
else if (iqentry_thrd[6]==iqentry_thrd[4])
4553
        nid4 = 3'd6;
4554
else if (iqentry_thrd[7]==iqentry_thrd[4])
4555
        nid4 = 3'd7;
4556
else if (iqentry_thrd[0]==iqentry_thrd[4])
4557
        nid4 = 3'd0;
4558
else if (iqentry_thrd[1]==iqentry_thrd[4])
4559
        nid4 = 3'd1;
4560
else if (iqentry_thrd[2]==iqentry_thrd[4])
4561
        nid4 = 3'd2;
4562
else if (iqentry_thrd[3]==iqentry_thrd[4])
4563
        nid4 = 3'd3;
4564
else
4565
        nid4 = 3'd4;
4566
 
4567
reg [`QBITS] nid5;
4568
always @*
4569
if (iqentry_thrd[6]==iqentry_thrd[5])
4570
        nid5 = 3'd6;
4571
else if (iqentry_thrd[7]==iqentry_thrd[5])
4572
        nid5 = 3'd7;
4573
else if (iqentry_thrd[0]==iqentry_thrd[5])
4574
        nid5 = 3'd0;
4575
else if (iqentry_thrd[1]==iqentry_thrd[5])
4576
        nid5 = 3'd1;
4577
else if (iqentry_thrd[2]==iqentry_thrd[5])
4578
        nid5 = 3'd2;
4579
else if (iqentry_thrd[3]==iqentry_thrd[5])
4580
        nid5 = 3'd3;
4581
else if (iqentry_thrd[4]==iqentry_thrd[5])
4582
        nid5 = 3'd4;
4583
else
4584
        nid5 = 3'd5;
4585
 
4586
reg [`QBITS] nid6;
4587
always @*
4588
if (iqentry_thrd[7]==iqentry_thrd[6])
4589
        nid6 = 3'd7;
4590
else if (iqentry_thrd[0]==iqentry_thrd[6])
4591
        nid6 = 3'd0;
4592
else if (iqentry_thrd[1]==iqentry_thrd[6])
4593
        nid6 = 3'd1;
4594
else if (iqentry_thrd[2]==iqentry_thrd[6])
4595
        nid6 = 3'd2;
4596
else if (iqentry_thrd[3]==iqentry_thrd[6])
4597
        nid6 = 3'd3;
4598
else if (iqentry_thrd[4]==iqentry_thrd[6])
4599
        nid6 = 3'd4;
4600
else if (iqentry_thrd[5]==iqentry_thrd[6])
4601
        nid6 = 3'd5;
4602
else
4603
        nid6 = 3'd6;
4604
 
4605
reg [`QBITS] nid7;
4606
always @*
4607
if (iqentry_thrd[0]==iqentry_thrd[7])
4608
        nid7 = 3'd0;
4609
else if (iqentry_thrd[1]==iqentry_thrd[7])
4610
        nid7 = 3'd1;
4611
else if (iqentry_thrd[2]==iqentry_thrd[7])
4612
        nid7 = 3'd2;
4613
else if (iqentry_thrd[3]==iqentry_thrd[7])
4614
        nid7 = 3'd3;
4615
else if (iqentry_thrd[4]==iqentry_thrd[7])
4616
        nid7 = 3'd4;
4617
else if (iqentry_thrd[5]==iqentry_thrd[7])
4618
        nid7 = 3'd5;
4619
else if (iqentry_thrd[6]==iqentry_thrd[7])
4620
        nid7 = 3'd6;
4621
else
4622
        nid7 = 3'd7;
4623
 
4624
// Search the queue for the next entry on the same thread.
4625
reg [`QBITS] nid;
4626
always @*
4627
if (iqentry_thrd[idp1(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4628
        nid = idp1(fcu_id);
4629
else if (iqentry_thrd[idp2(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4630
        nid = idp2(fcu_id);
4631
else if (iqentry_thrd[idp3(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4632
        nid = idp3(fcu_id);
4633
else if (iqentry_thrd[idp4(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4634
        nid = idp4(fcu_id);
4635
else if (iqentry_thrd[idp5(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4636
        nid = idp5(fcu_id);
4637
else if (iqentry_thrd[idp6(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4638
        nid = idp6(fcu_id);
4639
else if (iqentry_thrd[idp7(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4640
        nid = idp7(fcu_id);
4641
else
4642
        nid = fcu_id;
4643
 
4644
 
4645
assign  nextqd[0] = iqentry_sn[nid0] > iqentry_sn[0] || iqentry_v[0];
4646
assign  nextqd[1] = iqentry_sn[nid1] > iqentry_sn[1] || iqentry_v[1];
4647
assign  nextqd[2] = iqentry_sn[nid2] > iqentry_sn[2] || iqentry_v[2];
4648
assign  nextqd[3] = iqentry_sn[nid3] > iqentry_sn[3] || iqentry_v[3];
4649
assign  nextqd[4] = iqentry_sn[nid4] > iqentry_sn[4] || iqentry_v[4];
4650
assign  nextqd[5] = iqentry_sn[nid5] > iqentry_sn[5] || iqentry_v[5];
4651
assign  nextqd[6] = iqentry_sn[nid6] > iqentry_sn[6] || iqentry_v[6];
4652
assign  nextqd[7] = iqentry_sn[nid7] > iqentry_sn[7] || iqentry_v[7];
4653
 
4654
//assign nextqd = 8'hFF;
4655
 
4656
// Don't issue to the fcu until the following instruction is enqueued.
4657
// However, if the queue is full then issue anyway. A branch miss will likely occur.
4658
always @*//(could_issue or head0 or head1 or head2 or head3 or head4 or head5 or head6 or head7)
4659
begin
4660 49 robfinch
        iqentry_fcu_issue = {QENTRIES{1'b0}};
4661 48 robfinch
        if (fcu_done) begin
4662
    if (could_issue[head0] && iqentry_fc[head0] && nextqd[head0]) begin
4663
      iqentry_fcu_issue[head0] = `TRUE;
4664
    end
4665
    else if (could_issue[head1] && iqentry_fc[head1] && nextqd[head1])
4666
    begin
4667
      iqentry_fcu_issue[head1] = `TRUE;
4668
    end
4669
    else if (could_issue[head2] && iqentry_fc[head2] && nextqd[head2]
4670
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4671
    ) begin
4672
                iqentry_fcu_issue[head2] = `TRUE;
4673
    end
4674
    else if (could_issue[head3] && iqentry_fc[head3] && nextqd[head3]
4675
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4676
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4677
                ((!iqentry_v[head0])
4678
        &&   (!iqentry_v[head1]))
4679
        )
4680
    ) begin
4681
                iqentry_fcu_issue[head3] = `TRUE;
4682
    end
4683
    else if (could_issue[head4] && iqentry_fc[head4] && nextqd[head4]
4684
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4685
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4686
                ((!iqentry_v[head0])
4687
        &&   (!iqentry_v[head1]))
4688
        )
4689
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4690
                ((!iqentry_v[head0])
4691
        &&   (!iqentry_v[head1])
4692
        &&   (!iqentry_v[head2]))
4693
        )
4694
    ) begin
4695
                iqentry_fcu_issue[head4] = `TRUE;
4696
    end
4697
    else if (could_issue[head5] && iqentry_fc[head5] && nextqd[head5]
4698
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4699
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4700
                ((!iqentry_v[head0])
4701
        &&   (!iqentry_v[head1]))
4702
        )
4703
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4704
                ((!iqentry_v[head0])
4705
        &&   (!iqentry_v[head1])
4706
        &&   (!iqentry_v[head2]))
4707
        )
4708
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4709
                ((!iqentry_v[head0])
4710
        &&   (!iqentry_v[head1])
4711
        &&   (!iqentry_v[head2])
4712
        &&   (!iqentry_v[head3]))
4713
        )
4714
    ) begin
4715
                iqentry_fcu_issue[head5] = `TRUE;
4716
    end
4717
 
4718
`ifdef FULL_ISSUE_LOGIC
4719
    else if (could_issue[head6] && iqentry_fc[head6] && nextqd[head6]
4720
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4721
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4722
                ((!iqentry_v[head0])
4723
        &&   (!iqentry_v[head1]))
4724
        )
4725
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4726
                ((!iqentry_v[head0])
4727
        &&   (!iqentry_v[head1])
4728
        &&   (!iqentry_v[head2]))
4729
        )
4730
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4731
                ((!iqentry_v[head0])
4732
        &&   (!iqentry_v[head1])
4733
        &&   (!iqentry_v[head2])
4734
        &&   (!iqentry_v[head3]))
4735
        )
4736
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4737
                ((!iqentry_v[head0])
4738
        &&   (!iqentry_v[head1])
4739
        &&   (!iqentry_v[head2])
4740
        &&   (!iqentry_v[head3])
4741
        &&   (!iqentry_v[head4]))
4742
        )
4743
    ) begin
4744
                iqentry_fcu_issue[head6] = `TRUE;
4745
    end
4746
 
4747
    else if (could_issue[head7] && iqentry_fc[head7]
4748
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4749
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4750
                ((!iqentry_v[head0])
4751
        &&   (!iqentry_v[head1]))
4752
        )
4753
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4754
                ((!iqentry_v[head0])
4755
        &&   (!iqentry_v[head1])
4756
        &&   (!iqentry_v[head2]))
4757
        )
4758
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4759
                ((!iqentry_v[head0])
4760
        &&   (!iqentry_v[head1])
4761
        &&   (!iqentry_v[head2])
4762
        &&   (!iqentry_v[head3]))
4763
        )
4764
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4765
                ((!iqentry_v[head0])
4766
        &&   (!iqentry_v[head1])
4767
        &&   (!iqentry_v[head2])
4768
        &&   (!iqentry_v[head3])
4769
        &&   (!iqentry_v[head4]))
4770
        )
4771
    && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
4772
                ((!iqentry_v[head0])
4773
        &&   (!iqentry_v[head1])
4774
        &&   (!iqentry_v[head2])
4775
        &&   (!iqentry_v[head3])
4776
        &&   (!iqentry_v[head4])
4777
        &&   (!iqentry_v[head5]))
4778
        )
4779
    ) begin
4780
                iqentry_fcu_issue[head7] = `TRUE;
4781
        end
4782
`endif
4783
        end
4784
end
4785
 
4786
//
4787
// determine if the instructions ready to issue can, in fact, issue.
4788
// "ready" means that the instruction has valid operands but has not gone yet
4789
reg [1:0] issue_count, missue_count;
4790
always @*
4791
begin
4792
        issue_count = 0;
4793
         memissue[ head0 ] =    iqentry_memready[ head0 ];              // first in line ... go as soon as ready
4794
         if (memissue[head0])
4795
                issue_count = issue_count + 1;
4796
 
4797
         memissue[ head1 ] =    ~iqentry_stomp[head1] && iqentry_memready[ head1 ]              // addr and data are valid
4798 49 robfinch
                                        && issue_count < `NUM_MEM
4799 48 robfinch
                                        // ... and no preceding instruction is ready to go
4800
                                        //&& ~iqentry_memready[head0]
4801
                                        // ... and there is no address-overlap with any preceding instruction
4802
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
4803 49 robfinch
                                                || (iqentry_a1_v[head0] && iqentry_a1[head1][AMSB:3] != iqentry_a1[head0][AMSB:3]))
4804 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4805
                                        && (iqentry_rl[head1] ? iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0] : 1'b1)
4806
                                        // ... if a preivous op has the aquire bit set
4807
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4808
                                        // ... and, if it is a SW, there is no chance of it being undone
4809
                                        && (iqentry_load[head1] ||
4810
                                           !(iqentry_fc[head0]||iqentry_canex[head0]));
4811
         if (memissue[head1])
4812
                issue_count = issue_count + 1;
4813
 
4814
         memissue[ head2 ] =    ~iqentry_stomp[head2] && iqentry_memready[ head2 ]              // addr and data are valid
4815
                                        // ... and no preceding instruction is ready to go
4816 49 robfinch
                                        && issue_count < `NUM_MEM
4817 48 robfinch
                                        //&& ~iqentry_memready[head0]
4818
                                        //&& ~iqentry_memready[head1] 
4819
                                        // ... and there is no address-overlap with any preceding instruction
4820
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
4821 49 robfinch
                                                || (iqentry_a1_v[head0] && iqentry_a1[head2][AMSB:3] != iqentry_a1[head0][AMSB:3]))
4822 48 robfinch
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
4823 49 robfinch
                                                || (iqentry_a1_v[head1] && iqentry_a1[head2][AMSB:3] != iqentry_a1[head1][AMSB:3]))
4824 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4825
                                        && (iqentry_rl[head2] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4826
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4827
                                                                                         : 1'b1)
4828
                                        // ... if a preivous op has the aquire bit set
4829
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4830
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4831
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4832 49 robfinch
            && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4833
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4834 48 robfinch
                                        // ... and, if it is a SW, there is no chance of it being undone
4835
                                        && (iqentry_load[head2] ||
4836
                                              !(iqentry_fc[head0]||iqentry_canex[head0])
4837
                                           && !(iqentry_fc[head1]||iqentry_canex[head1]));
4838
         if (memissue[head2])
4839
                issue_count = issue_count + 1;
4840
 
4841
         memissue[ head3 ] =    ~iqentry_stomp[head3] && iqentry_memready[ head3 ]              // addr and data are valid
4842
                                        // ... and no preceding instruction is ready to go
4843 49 robfinch
                                        && issue_count < `NUM_MEM
4844 48 robfinch
                                        //&& ~iqentry_memready[head0]
4845
                                        //&& ~iqentry_memready[head1] 
4846
                                        //&& ~iqentry_memready[head2] 
4847
                                        // ... and there is no address-overlap with any preceding instruction
4848
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
4849 49 robfinch
                                                || (iqentry_a1_v[head0] && iqentry_a1[head3][AMSB:3] != iqentry_a1[head0][AMSB:3]))
4850 48 robfinch
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
4851 49 robfinch
                                                || (iqentry_a1_v[head1] && iqentry_a1[head3][AMSB:3] != iqentry_a1[head1][AMSB:3]))
4852 48 robfinch
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])
4853 49 robfinch
                                                || (iqentry_a1_v[head2] && iqentry_a1[head3][AMSB:3] != iqentry_a1[head2][AMSB:3]))
4854 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4855
                                        && (iqentry_rl[head3] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4856
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4857
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4858
                                                                                         : 1'b1)
4859
                                        // ... if a preivous op has the aquire bit set
4860
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4861
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4862
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4863
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4864 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4865
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4866 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4867
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4868
                                )
4869 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4870
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4871 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4872
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4873
                                )
4874
                    // ... and, if it is a SW, there is no chance of it being undone
4875
                                        && (iqentry_load[head3] ||
4876
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4877
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4878
                       && !(iqentry_fc[head2]||iqentry_canex[head2]));
4879
         if (memissue[head3])
4880
                issue_count = issue_count + 1;
4881
 
4882
         memissue[ head4 ] =    ~iqentry_stomp[head4] && iqentry_memready[ head4 ]              // addr and data are valid
4883
                                        // ... and no preceding instruction is ready to go
4884 49 robfinch
                                        && issue_count < `NUM_MEM
4885 48 robfinch
                                        //&& ~iqentry_memready[head0]
4886
                                        //&& ~iqentry_memready[head1] 
4887
                                        //&& ~iqentry_memready[head2] 
4888
                                        //&& ~iqentry_memready[head3] 
4889
                                        // ... and there is no address-overlap with any preceding instruction
4890
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
4891 49 robfinch
                                                || (iqentry_a1_v[head0] && iqentry_a1[head4][AMSB:3] != iqentry_a1[head0][AMSB:3]))
4892 48 robfinch
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
4893 49 robfinch
                                                || (iqentry_a1_v[head1] && iqentry_a1[head4][AMSB:3] != iqentry_a1[head1][AMSB:3]))
4894 48 robfinch
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])
4895 49 robfinch
                                                || (iqentry_a1_v[head2] && iqentry_a1[head4][AMSB:3] != iqentry_a1[head2][AMSB:3]))
4896 48 robfinch
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3])
4897 49 robfinch
                                                || (iqentry_a1_v[head3] && iqentry_a1[head4][AMSB:3] != iqentry_a1[head3][AMSB:3]))
4898 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4899
                                        && (iqentry_rl[head4] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4900
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4901
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4902
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4903
                                                                                         : 1'b1)
4904
                                        // ... if a preivous op has the aquire bit set
4905
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4906
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4907
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4908
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4909
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4910 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4911
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4912 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4913
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4914
                                )
4915 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
4916 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4917
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4918
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4919
                                )
4920
                                && (!(iqentry_v[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4921 49 robfinch
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4922 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4923
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4924
                                )
4925 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
4926 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4927
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4928
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4929
                                )
4930
                                        // ... and, if it is a SW, there is no chance of it being undone
4931
                                        && (iqentry_load[head4] ||
4932
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4933
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4934
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
4935
                       && !(iqentry_fc[head3]||iqentry_canex[head3]));
4936
         if (memissue[head4])
4937
                issue_count = issue_count + 1;
4938
 
4939
         memissue[ head5 ] =    ~iqentry_stomp[head5] && iqentry_memready[ head5 ]              // addr and data are valid
4940
                                        // ... and no preceding instruction is ready to go
4941 49 robfinch
                                        && issue_count < `NUM_MEM
4942 48 robfinch
                                        //&& ~iqentry_memready[head0]
4943
                                        //&& ~iqentry_memready[head1] 
4944
                                        //&& ~iqentry_memready[head2] 
4945
                                        //&& ~iqentry_memready[head3] 
4946
                                        //&& ~iqentry_memready[head4] 
4947
                                        // ... and there is no address-overlap with any preceding instruction
4948
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
4949 49 robfinch
                                                || (iqentry_a1_v[head0] && iqentry_a1[head5][AMSB:3] != iqentry_a1[head0][AMSB:3]))
4950 48 robfinch
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
4951 49 robfinch
                                                || (iqentry_a1_v[head1] && iqentry_a1[head5][AMSB:3] != iqentry_a1[head1][AMSB:3]))
4952 48 robfinch
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])
4953 49 robfinch
                                                || (iqentry_a1_v[head2] && iqentry_a1[head5][AMSB:3] != iqentry_a1[head2][AMSB:3]))
4954 48 robfinch
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3])
4955 49 robfinch
                                                || (iqentry_a1_v[head3] && iqentry_a1[head5][AMSB:3] != iqentry_a1[head3][AMSB:3]))
4956 48 robfinch
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4])
4957 49 robfinch
                                                || (iqentry_a1_v[head4] && iqentry_a1[head5][AMSB:3] != iqentry_a1[head4][AMSB:3]))
4958 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4959
                                        && (iqentry_rl[head5] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4960
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4961
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4962
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4963
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
4964
                                                                                         : 1'b1)
4965
                                        // ... if a preivous op has the aquire bit set
4966
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4967
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4968
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4969
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4970
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
4971
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4972 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4973
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4974 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4975
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4976
                                )
4977 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
4978 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4979
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4980
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4981
                                )
4982 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
4983 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4984
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4985
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4986
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
4987
                                )
4988 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4989
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4990 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4991
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4992
                                )
4993 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
4994 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4995
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4996
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4997
                                )
4998 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
4999 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5000
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5001
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5002
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
5003
                                )
5004
                                        // ... and, if it is a SW, there is no chance of it being undone
5005
                                        && (iqentry_load[head5] ||
5006
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
5007
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
5008
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
5009
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
5010
                       && !(iqentry_fc[head4]||iqentry_canex[head4]));
5011
         if (memissue[head5])
5012
                issue_count = issue_count + 1;
5013
 
5014
`ifdef FULL_ISSUE_LOGIC
5015
         memissue[ head6 ] =    ~iqentry_stomp[head6] && iqentry_memready[ head6 ]              // addr and data are valid
5016
                                        // ... and no preceding instruction is ready to go
5017 49 robfinch
                                        && issue_count < `NUM_MEM
5018 48 robfinch
                                        //&& ~iqentry_memready[head0]
5019
                                        //&& ~iqentry_memready[head1] 
5020
                                        //&& ~iqentry_memready[head2] 
5021
                                        //&& ~iqentry_memready[head3] 
5022
                                        //&& ~iqentry_memready[head4] 
5023
                                        //&& ~iqentry_memready[head5] 
5024
                                        // ... and there is no address-overlap with any preceding instruction
5025
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
5026 49 robfinch
                                                || (iqentry_a1_v[head0] && iqentry_a1[head6][AMSB:3] != iqentry_a1[head0][AMSB:3]))
5027 48 robfinch
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
5028 49 robfinch
                                                || (iqentry_a1_v[head1] && iqentry_a1[head6][AMSB:3] != iqentry_a1[head1][AMSB:3]))
5029 48 robfinch
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])
5030 49 robfinch
                                                || (iqentry_a1_v[head2] && iqentry_a1[head6][AMSB:3] != iqentry_a1[head2][AMSB:3]))
5031 48 robfinch
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3])
5032 49 robfinch
                                                || (iqentry_a1_v[head3] && iqentry_a1[head6][AMSB:3] != iqentry_a1[head3][AMSB:3]))
5033 48 robfinch
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4])
5034 49 robfinch
                                                || (iqentry_a1_v[head4] && iqentry_a1[head6][AMSB:3] != iqentry_a1[head4][AMSB:3]))
5035 48 robfinch
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5])
5036 49 robfinch
                                                || (iqentry_a1_v[head5] && iqentry_a1[head6][AMSB:3] != iqentry_a1[head5][AMSB:3]))
5037 48 robfinch
                                        && (iqentry_rl[head6] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
5038
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
5039
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
5040
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
5041
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
5042
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
5043
                                                                                         : 1'b1)
5044
                                        // ... if a preivous op has the aquire bit set
5045
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
5046
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
5047
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
5048
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
5049
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
5050
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
5051
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5052 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
5053
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
5054 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5055
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
5056
                                )
5057 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
5058 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5059
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5060
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
5061
                                )
5062 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
5063 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5064
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5065
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5066
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
5067
                                )
5068 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memsb[head5]) ||
5069 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5070
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5071
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5072
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5073
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
5074
                                )
5075 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
5076
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
5077 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5078
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
5079
                                )
5080 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
5081 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5082
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5083
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
5084
                                )
5085 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
5086 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5087
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5088
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5089
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
5090
                                )
5091 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memdb[head5]) ||
5092 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5093
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5094
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5095
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5096
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
5097
                                )
5098
                                        // ... and, if it is a SW, there is no chance of it being undone
5099
                                        && (iqentry_load[head6] ||
5100
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
5101
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
5102
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
5103
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
5104
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
5105
                       && !(iqentry_fc[head5]||iqentry_canex[head5]));
5106
         if (memissue[head6])
5107
                issue_count = issue_count + 1;
5108
 
5109
         memissue[ head7 ] =    ~iqentry_stomp[head7] && iqentry_memready[ head7 ]              // addr and data are valid
5110
                                        // ... and no preceding instruction is ready to go
5111 49 robfinch
                                        && issue_count < `NUM_MEM
5112 48 robfinch
                                        //&& ~iqentry_memready[head0]
5113
                                        //&& ~iqentry_memready[head1] 
5114
                                        //&& ~iqentry_memready[head2] 
5115
                                        //&& ~iqentry_memready[head3] 
5116
                                        //&& ~iqentry_memready[head4] 
5117
                                        //&& ~iqentry_memready[head5] 
5118
                                        //&& ~iqentry_memready[head6] 
5119
                                        // ... and there is no address-overlap with any preceding instruction
5120
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
5121 49 robfinch
                                                || (iqentry_a1_v[head0] && iqentry_a1[head7][AMSB:3] != iqentry_a1[head0][AMSB:3]))
5122 48 robfinch
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
5123 49 robfinch
                                                || (iqentry_a1_v[head1] && iqentry_a1[head7][AMSB:3] != iqentry_a1[head1][AMSB:3]))
5124 48 robfinch
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])
5125 49 robfinch
                                                || (iqentry_a1_v[head2] && iqentry_a1[head7][AMSB:3] != iqentry_a1[head2][AMSB:3]))
5126 48 robfinch
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3])
5127 49 robfinch
                                                || (iqentry_a1_v[head3] && iqentry_a1[head7][AMSB:3] != iqentry_a1[head3][AMSB:3]))
5128 48 robfinch
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4])
5129 49 robfinch
                                                || (iqentry_a1_v[head4] && iqentry_a1[head7][AMSB:3] != iqentry_a1[head4][AMSB:3]))
5130 48 robfinch
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5])
5131 49 robfinch
                                                || (iqentry_a1_v[head5] && iqentry_a1[head7][AMSB:3] != iqentry_a1[head5][AMSB:3]))
5132 48 robfinch
                                        && (!iqentry_mem[head6] || (iqentry_agen[head6] & iqentry_out[head6])
5133 49 robfinch
                                                || (iqentry_a1_v[head6] && iqentry_a1[head7][AMSB:3] != iqentry_a1[head6][AMSB:3]))
5134 48 robfinch
                                        && (iqentry_rl[head7] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
5135
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
5136
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
5137
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
5138
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
5139
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
5140
                                                                                 && (iqentry_done[head6] || !iqentry_v[head6] || !iqentry_mem[head6])
5141
                                                                                         : 1'b1)
5142
                                        // ... if a preivous op has the aquire bit set
5143
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
5144
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
5145
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
5146
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
5147
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
5148
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
5149
                                        && !(iqentry_aq[head6] && iqentry_v[head6])
5150
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5151 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
5152
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
5153 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5154
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
5155
                                )
5156 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
5157 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5158
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5159
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
5160
                                )
5161 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
5162 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5163
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5164
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5165
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
5166
                                )
5167 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memsb[head5]) ||
5168 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5169
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5170
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5171
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5172
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
5173
                                )
5174 49 robfinch
                    && (!(iqentry_iv[head6] && iqentry_memsb[head6]) ||
5175 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5176
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5177
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5178
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5179
                                &&   (iqentry_done[head4] || !iqentry_v[head4])
5180
                                &&   (iqentry_done[head5] || !iqentry_v[head5]))
5181
                                )
5182 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
5183
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
5184 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5185
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
5186
                                )
5187 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
5188 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5189
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5190
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
5191
                                )
5192 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
5193 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5194
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5195
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5196
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
5197
                                )
5198 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memdb[head5]) ||
5199 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5200
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5201
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5202
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5203
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
5204
                                )
5205 49 robfinch
                    && (!(iqentry_iv[head6] && iqentry_memdb[head6]) ||
5206 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5207
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5208
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5209
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5210
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4])
5211
                                && (!iqentry_mem[head5] || iqentry_done[head5] || !iqentry_v[head5]))
5212
                                )
5213
                                        // ... and, if it is a SW, there is no chance of it being undone
5214
                                        && (iqentry_load[head7] ||
5215
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
5216
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
5217
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
5218
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
5219
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
5220
                       && !(iqentry_fc[head5]||iqentry_canex[head5])
5221
                       && !(iqentry_fc[head6]||iqentry_canex[head6]));
5222
`endif
5223
end
5224
 
5225 49 robfinch
reg [2:0] wbptr;
5226
always @*
5227
begin
5228
        // Crashes sim
5229
//      wbptr <= `WB_DEPTH-1;
5230
//      if (wb_v==8'h0)
5231
//              wbptr <= 3'd0;
5232
//      else
5233
//      begin
5234
//              for (n = `WB_DEPTH-2; n >= 0; n = n - 1)
5235
//                      if (wb_v[n] && wbptr==`WB_DEPTH-1)
5236
//                              wbptr <= n + 1;
5237
//      end
5238
        if (wb_v[6])
5239
                wbptr <= 3'd7;
5240
        else if (wb_v[5])
5241
                wbptr <= 3'd6;
5242
        else if (wb_v[4])
5243
                wbptr <= 3'd5;
5244
        else if (wb_v[3])
5245
                wbptr <= 3'd4;
5246
        else if (wb_v[2])
5247
                wbptr <= 3'd3;
5248
        else if (wb_v[1])
5249
                wbptr <= 3'd2;
5250
        else if (wb_v[0])
5251
                wbptr <= 3'd1;
5252
        else
5253
                wbptr <= 3'd0;
5254
end
5255
 
5256 48 robfinch
// Stomp logic for branch miss.
5257
 
5258
FT64_stomp #(QENTRIES) ustmp1
5259
(
5260
        .branchmiss(branchmiss),
5261
        .branchmiss_thrd(branchmiss_thrd),
5262
        .missid(missid),
5263
        .head0(head0),
5264
        .thrd(iqentry_thrd),
5265
        .iqentry_v(iqentry_v),
5266
        .stomp(iqentry_stomp)
5267
);
5268
 
5269
always @*
5270
begin
5271
        if (iqentry_stomp[0] && IsRet(iqentry_instr[0]))
5272
                stompedOnRets = stompedOnRets + 4'd1;
5273
        if (iqentry_stomp[1] && IsRet(iqentry_instr[1]))
5274
                stompedOnRets = stompedOnRets + 4'd1;
5275
        if (iqentry_stomp[2] && IsRet(iqentry_instr[2]))
5276
                stompedOnRets = stompedOnRets + 4'd1;
5277
        if (iqentry_stomp[3] && IsRet(iqentry_instr[3]))
5278
                stompedOnRets = stompedOnRets + 4'd1;
5279
        if (iqentry_stomp[4] && IsRet(iqentry_instr[4]))
5280
                stompedOnRets = stompedOnRets + 4'd1;
5281
        if (iqentry_stomp[5] && IsRet(iqentry_instr[5]))
5282
                stompedOnRets = stompedOnRets + 4'd1;
5283
        if (iqentry_stomp[6] && IsRet(iqentry_instr[6]))
5284
                stompedOnRets = stompedOnRets + 4'd1;
5285
        if (iqentry_stomp[7] && IsRet(iqentry_instr[7]))
5286
                stompedOnRets = stompedOnRets + 4'd1;
5287
end
5288
 
5289 49 robfinch
reg id1_vi, id2_vi, id3_vi;
5290
wire [4:0] id1_ido, id2_ido, id3_ido;
5291
wire id1_vo, id2_vo, id3_vo;
5292
wire id1_clk, id2_clk, id3_clk;
5293 48 robfinch
 
5294 49 robfinch
// Always at least one decoder
5295 50 robfinch
assign id1_clk = clk_i;
5296
//BUFGCE uclkb2
5297
//(
5298
//      .I(clk_i),
5299
//      .CE(id1_available),
5300
//      .O(id1_clk)
5301
//);
5302 48 robfinch
 
5303
FT64_idecoder uid1
5304
(
5305
        .clk(id1_clk),
5306
        .idv_i(id1_vi),
5307
        .id_i(id1_id),
5308
        .instr(id1_instr),
5309
        .ven(id1_ven),
5310
        .vl(id1_vl),
5311
        .thrd(id1_thrd),
5312
        .predict_taken(id1_pt),
5313
        .Rt(id1_Rt),
5314
        .bus(id1_bus),
5315
        .id_o(id1_ido),
5316
        .idv_o(id1_vo)
5317
);
5318
 
5319 49 robfinch
generate begin : gIDUInst
5320
if (`NUM_IDU > 1) begin
5321 50 robfinch
//BUFGCE uclkb3
5322
//(
5323
//      .I(clk_i),
5324
//      .CE(id2_available),
5325
//      .O(id2_clk)
5326
//);
5327
assign id2_clk = clk_i;
5328 48 robfinch
 
5329
FT64_idecoder uid2
5330
(
5331
        .clk(id2_clk),
5332
        .idv_i(id2_vi),
5333
        .id_i(id2_id),
5334
        .instr(id2_instr),
5335
        .ven(id2_ven),
5336
        .vl(id2_vl),
5337
        .thrd(id2_thrd),
5338
        .predict_taken(id2_pt),
5339
        .Rt(id2_Rt),
5340
        .bus(id2_bus),
5341
        .id_o(id2_ido),
5342
        .idv_o(id2_vo)
5343
);
5344 49 robfinch
end
5345
if (`NUM_IDU > 2) begin
5346 50 robfinch
//BUFGCE uclkb4
5347
//(
5348
//      .I(clk_i),
5349
//      .CE(id3_available),
5350
//      .O(id3_clk)
5351
//);
5352
assign id3_clk = clk_i;
5353 48 robfinch
 
5354 49 robfinch
FT64_idecoder uid2
5355
(
5356
        .clk(id3_clk),
5357
        .idv_i(id3_vi),
5358
        .id_i(id3_id),
5359
        .instr(id3_instr),
5360
        .ven(id3_ven),
5361
        .vl(id3_vl),
5362
        .thrd(id3_thrd),
5363
        .predict_taken(id3_pt),
5364
        .Rt(id3_Rt),
5365
        .bus(id3_bus),
5366
        .id_o(id3_ido),
5367
        .idv_o(id3_vo)
5368
);
5369
end
5370
end
5371
endgenerate
5372
 
5373 48 robfinch
//
5374
// EXECUTE
5375
//
5376
reg [63:0] csr_r;
5377
always @*
5378
    read_csr(alu0_instr[29:18],csr_r,alu0_thrd);
5379
FT64_alu #(.BIG(1'b1),.SUP_VECTOR(SUP_VECTOR)) ualu0 (
5380
  .rst(rst),
5381
  .clk(clk),
5382
  .ld(alu0_ld),
5383
  .abort(1'b0),
5384
  .instr(alu0_instr),
5385
  .a(alu0_argA),
5386
  .b(alu0_argB),
5387
  .c(alu0_argC),
5388
  .pc(alu0_pc),
5389
//    .imm(alu0_argI),
5390
  .tgt(alu0_tgt),
5391
  .ven(alu0_ven),
5392
  .vm(vm[alu0_instr[25:23]]),
5393
  .sbl(sbl),
5394
  .sbu(sbu),
5395
  .csr(csr_r),
5396
  .o(alu0_bus),
5397
  .ob(alu0b_bus),
5398
  .done(alu0_done),
5399
  .idle(alu0_idle),
5400
  .excen(aec[4:0]),
5401
  .exc(alu0_exc),
5402
  .thrd(alu0_thrd),
5403
  .mem(alu0_mem),
5404
  .shift48(alu0_shft48)
5405
);
5406 49 robfinch
generate begin : gAluInst
5407
if (`NUM_ALU > 1) begin
5408 48 robfinch
FT64_alu #(.BIG(1'b0),.SUP_VECTOR(SUP_VECTOR)) ualu1 (
5409
  .rst(rst),
5410
  .clk(clk),
5411
  .ld(alu1_ld),
5412
  .abort(1'b0),
5413
  .instr(alu1_instr),
5414
  .a(alu1_argA),
5415
  .b(alu1_argB),
5416
  .c(alu1_argC),
5417
  .pc(alu1_pc),
5418
  //.imm(alu1_argI),
5419
  .tgt(alu1_tgt),
5420
  .ven(alu1_ven),
5421
  .vm(vm[alu1_instr[25:23]]),
5422
  .sbl(sbl),
5423
  .sbu(sbu),
5424
  .csr(64'd0),
5425
  .o(alu1_bus),
5426
  .ob(alu1b_bus),
5427
  .done(alu1_done),
5428
  .idle(alu1_idle),
5429
  .excen(aec[4:0]),
5430
  .exc(alu1_exc),
5431
  .thrd(1'b0),
5432
  .mem(alu1_mem),
5433
  .shift48(alu1_shft48)
5434
);
5435 49 robfinch
end
5436
end
5437
endgenerate
5438
 
5439
generate begin : gFPUInst
5440
if (`NUM_FPU > 0) begin
5441
wire fpu1_clk;
5442 50 robfinch
//BUFGCE ufpc1
5443
//(
5444
//      .I(clk_i),
5445
//      .CE(fpu1_available),
5446
//      .O(fpu1_clk)
5447
//);
5448
assign fpu1_clk = clk_i;
5449
 
5450 48 robfinch
fpUnit ufp1
5451
(
5452
  .rst(rst),
5453 49 robfinch
  .clk(fpu1_clk),
5454 48 robfinch
  .clk4x(clk4x),
5455
  .ce(1'b1),
5456 49 robfinch
  .ir(fpu1_instr),
5457
  .ld(fpu1_ld),
5458
  .a(fpu1_argA),
5459
  .b(fpu1_argB),
5460
  .imm(fpu1_argI),
5461
  .o(fpu1_bus),
5462 48 robfinch
  .csr_i(),
5463 49 robfinch
  .status(fpu1_status),
5464 48 robfinch
  .exception(),
5465 49 robfinch
  .done(fpu1_done)
5466 48 robfinch
);
5467 49 robfinch
end
5468
if (`NUM_FPU > 1) begin
5469
wire fpu2_clk;
5470 50 robfinch
//BUFGCE ufpc2
5471
//(
5472
//      .I(clk_i),
5473
//      .CE(fpu2_available),
5474
//      .O(fpu2_clk)
5475
//);
5476
assign fpu2_clk = clk_i;
5477 49 robfinch
fpUnit ufp1
5478
(
5479
  .rst(rst),
5480
  .clk(fpu2_clk),
5481
  .clk4x(clk4x),
5482
  .ce(1'b1),
5483
  .ir(fpu2_instr),
5484
  .ld(fpu2_ld),
5485
  .a(fpu2_argA),
5486
  .b(fpu2_argB),
5487
  .imm(fpu2_argI),
5488
  .o(fpu2_bus),
5489
  .csr_i(),
5490
  .status(fpu2_status),
5491
  .exception(),
5492
  .done(fpu2_done)
5493
);
5494
end
5495
end
5496
endgenerate
5497 48 robfinch
 
5498 49 robfinch
assign fpu_exc = fpu1_available ? (|fpu1_status[15:0] ? `FLT_FLT : `FLT_NONE) : `FLT_UNIMP;
5499
 
5500 48 robfinch
assign  alu0_v = alu0_dataready,
5501
        alu1_v = alu1_dataready;
5502
assign  alu0_id = alu0_sourceid,
5503
            alu1_id = alu1_sourceid;
5504 49 robfinch
assign  fpu1_v = fpu1_dataready;
5505
assign  fpu1_id = fpu1_sourceid;
5506
assign  fpu2_v = fpu2_dataready;
5507
assign  fpu2_id = fpu2_sourceid;
5508 48 robfinch
 
5509
`ifdef SUPPORT_SMT
5510
wire [1:0] olm = ol[fcu_thrd];
5511
`else
5512
wire [1:0] olm = ol;
5513
`endif
5514
 
5515
assign  fcu_v = fcu_dataready;
5516
assign  fcu_id = fcu_sourceid;
5517
 
5518
wire [4:0] fcmpo;
5519
wire fnanx;
5520
fp_cmp_unit ufcmp1 (fcu_argA, fcu_argB, fcmpo, fnanx);
5521
 
5522
wire fcu_takb;
5523
 
5524
always @*
5525
begin
5526
    fcu_exc <= `FLT_NONE;
5527
    casez(fcu_instr[`INSTRUCTION_OP])
5528
    `CHK:   begin
5529
                if (fcu_instr[21])
5530
                    fcu_exc <= fcu_argA >= fcu_argB && fcu_argA < fcu_argC ? `FLT_NONE : `FLT_CHK;
5531
            end
5532
    `REX:
5533
        case(olm)
5534
        `OL_USER:   fcu_exc <= `FLT_PRIV;
5535
        default:    ;
5536
        endcase
5537
        endcase
5538
end
5539
 
5540
FT64_EvalBranch ube1
5541
(
5542
        .instr(fcu_instr),
5543
        .a(fcu_argA),
5544
        .b(fcu_argB),
5545
        .c(fcu_argC),
5546
        .takb(fcu_takb)
5547
);
5548
 
5549
FT64_FCU_Calc ufcuc1
5550
(
5551
        .ol(olm),
5552
        .instr(fcu_instr),
5553
        .tvec(tvec[fcu_instr[14:13]]),
5554
        .a(fcu_argA),
5555
        .i(fcu_argI),
5556
        .pc(fcu_pc),
5557
        .im(im),
5558
        .waitctr(waitctr),
5559
        .bus(fcu_bus)
5560
);
5561
 
5562
always @*
5563
begin
5564
case(fcu_instr[`INSTRUCTION_OP])
5565
`R2:    fcu_misspc = fcu_argB;  // RTI (we don't bother fully decoding this as it's the only R2)
5566
`RET:   fcu_misspc = fcu_argB;
5567
`REX:   fcu_misspc = fcu_bus;
5568
`BRK:   fcu_misspc = {tvec[0][31:8], 1'b0, olm, 5'h0};
5569
`JAL:   fcu_misspc = fcu_argA + fcu_argI;
5570
//`CHK: fcu_misspc = fcu_nextpc + fcu_argI;     // Handled as an instruction exception
5571
// Default: branch
5572
default:        fcu_misspc = fcu_takb ? fcu_nextpc + fcu_brdisp : fcu_nextpc;
5573
endcase
5574
fcu_misspc[0] = 1'b0;
5575
end
5576
 
5577
// To avoid false branch mispredicts the branch isn't evaluated until the
5578
// following instruction queues. The address of the next instruction is
5579
// looked at to see if the BTB predicted correctly.
5580
 
5581
wire fcu_brk_miss = (IsBrk(fcu_instr) || IsRTI(fcu_instr)) && fcu_v;
5582
wire fcu_ret_miss = IsRet(fcu_instr) && fcu_v && (fcu_argB != iqentry_pc[idp2(fcu_id)]);
5583
wire fcu_jal_miss = IsJAL(fcu_instr) && fcu_v && fcu_argA + fcu_argI != iqentry_pc[idp2(fcu_id)];
5584
wire fcu_followed = iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]];
5585
always @*
5586
if (fcu_dataready) begin
5587
//      if (fcu_timeout[7])
5588
//              fcu_branchmiss = TRUE;
5589
        // Break and RTI switch register sets, and so are always treated as a branch miss in order to
5590
        // flush the pipeline. Hardware interrupts also stream break instructions so they need to 
5591
        // flushed from the queue so the interrupt is recognized only once.
5592
        // BRK and RTI are handled as excmiss types which are processed during the commit stage.
5593
//      else
5594
        if (fcu_brk_miss)
5595
                fcu_branchmiss = TRUE & ~fcu_clearbm;
5596
    // the following instruction is queued
5597
        else
5598
        if (fcu_followed) begin
5599
`ifdef SUPPORT_SMT
5600
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol[fcu_thrd]) && fcu_v)
5601
`else
5602
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol) && fcu_v)
5603
`endif
5604
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5605
                else if (fcu_ret_miss)
5606
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5607
                else if (IsBranch(fcu_instr) && fcu_v && (((fcu_takb && (~fcu_bt || (fcu_misspc != iqentry_pc[nid]))) ||
5608
                                            (~fcu_takb && ( fcu_bt || (fcu_pc + 32'd4 != iqentry_pc[nid])))) || iqentry_v[nid]))
5609
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5610
                else if (fcu_jal_miss)
5611
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5612
                else if (fcu_instr[`INSTRUCTION_OP] == `CHK && ~fcu_takb && fcu_v)
5613
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5614
                else
5615
                    fcu_branchmiss = FALSE;
5616
        end
5617
        else begin
5618
                // Stuck at the head and can't finish because there's still an uncommitted instruction in the queue.
5619
                // -> cause a branch miss to clear the queue.
5620
                if (iqentry_v[nid] && !IsCall(fcu_instr) && !IsJmp(fcu_instr) && fcu_v)
5621
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5622
                else
5623
                /*
5624
                if (fcu_id==head0 && iqentry_v[idp1(head0)]) begin
5625
                        if ((fcu_bus[0] && (~fcu_bt || (fcu_misspc == iqentry_pc[nid]))) ||
5626
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 == iqentry_pc[nid]))))
5627
                        fcu_branchmiss = FALSE;
5628
                    else
5629
                                fcu_branchmiss = TRUE;
5630
                end
5631
                else if (fcu_id==head1 && iqentry_v[idp2(head1)]) begin
5632
                        if ((fcu_bus[0] && (~fcu_bt || (fcu_misspc == iqentry_pc[nid]))) ||
5633
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 == iqentry_pc[nid]))))
5634
                        fcu_branchmiss = FALSE;
5635
                    else
5636
                                fcu_branchmiss = TRUE;
5637
                end
5638
                else*/
5639
                        fcu_branchmiss = FALSE;
5640
        end
5641
end
5642
else
5643
        fcu_branchmiss = FALSE;
5644
/*
5645
assign fcu_branchmiss = fcu_dataready &&
5646
            // and the following instruction is queued
5647
            iqentry_v[idp1(fcu_id)] && iqentry_sn[idp1(fcu_id)]==iqentry_sn[fcu_id[`QBITS]]+5'd1 &&
5648
            ((IsBrk(fcu_instr) || IsRTI(fcu_instr)) ||
5649
            ((fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol)) ||
5650
            (fcu_instr[`INSTRUCTION_OP] == `CHK && ~fcu_bus[0]) ||
5651
                   (IsRTI(fcu_instr) && epc != iqentry_pc[idp1(fcu_id[`QBITS])]) ||
5652
                   // If it's a ret and the return address doesn't match the address of the
5653
                   // next queued instruction then the return prediction was wrong.
5654
                   (/*IsRet(fcu_instr) &&
5655
                     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)])) ||
5656
                   (IsBrk(fcu_instr) && {tvec[0][31:8], ol, 5'h0} != iqentry_pc[idp1(fcu_id)]) ||
5657
//                         (fcu_instr[`INSTRUCTION_OP] == `BccR && fcu_argC != iqentry_pc[(fcu_id[`QBITS]+3'd1)&7] && fcu_bus[0]) ||
5658
                    (IsBranch(fcu_instr) && ((fcu_bus[0] && (~fcu_bt || (fcu_misspc != iqentry_pc[idp1(fcu_id)]))) ||
5659
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 != iqentry_pc[idp1(fcu_id)]))))) ||
5660
                    (IsJAL(fcu_instr)) && fcu_argA + fcu_argI != iqentry_pc[idp1(fcu_id)]));
5661
*/
5662
 
5663
// Flow control ops don't issue until the next instruction queues.
5664
// The fcu_timeout tracks how long the flow control op has been in the "out" state.
5665
// It should never be that way more than a couple of cycles. Sometimes the fcu_wr pulse got missed
5666
// because the following instruction got stomped on during a branchmiss, hence iqentry_v isn't true.
5667
wire fcu_wr = (fcu_v && iqentry_v[nid] && iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]]);//      // && iqentry_v[nid]
5668
//                                      && fcu_instr==iqentry_instr[fcu_id[`QBITS]]);// || fcu_timeout==8'h05;
5669
 
5670
FT64_RMW_alu urmwalu0 (rmw_instr, rmw_argA, rmw_argB, rmw_argC, rmw_res);
5671
 
5672
//assign fcu_done = IsWait(fcu_instr) ? ((waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]]) :
5673
//                                      fcu_v && iqentry_v[idp1(fcu_id)] && iqentry_sn[idp1(fcu_id)]==iqentry_sn[fcu_id[`QBITS]]+5'd1;
5674
 
5675
// An exception in a committing instruction takes precedence
5676
/*
5677
Too slow. Needs to be registered
5678
assign  branchmiss = excmiss|fcu_branchmiss,
5679
    misspc = excmiss ? excmisspc : fcu_misspc,
5680
    missid = excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
5681
assign branchmiss_thrd =  excmiss ? excthrd : fcu_thrd;
5682
*/
5683
 
5684
//
5685
// additional DRAM-enqueue logic
5686
 
5687
assign dram_avail = (dram0 == `DRAMSLOT_AVAIL || dram1 == `DRAMSLOT_AVAIL || dram2 == `DRAMSLOT_AVAIL);
5688
 
5689
assign  iqentry_memopsvalid[0] = (iqentry_mem[0] & iqentry_a2_v[0] & iqentry_agen[0]),
5690
    iqentry_memopsvalid[1] = (iqentry_mem[1] & iqentry_a2_v[1] & iqentry_agen[1]),
5691
    iqentry_memopsvalid[2] = (iqentry_mem[2] & iqentry_a2_v[2] & iqentry_agen[2]),
5692
    iqentry_memopsvalid[3] = (iqentry_mem[3] & iqentry_a2_v[3] & iqentry_agen[3]),
5693
    iqentry_memopsvalid[4] = (iqentry_mem[4] & iqentry_a2_v[4] & iqentry_agen[4]),
5694
    iqentry_memopsvalid[5] = (iqentry_mem[5] & iqentry_a2_v[5] & iqentry_agen[5]),
5695
    iqentry_memopsvalid[6] = (iqentry_mem[6] & iqentry_a2_v[6] & iqentry_agen[6]),
5696
    iqentry_memopsvalid[7] = (iqentry_mem[7] & iqentry_a2_v[7] & iqentry_agen[7]);
5697
 
5698
assign  iqentry_memready[0] = (iqentry_v[0] & iqentry_memopsvalid[0] & ~iqentry_memissue[0] & ~iqentry_done[0] & ~iqentry_out[0] & ~iqentry_stomp[0]),
5699
    iqentry_memready[1] = (iqentry_v[1] & iqentry_memopsvalid[1] & ~iqentry_memissue[1] & ~iqentry_done[1] & ~iqentry_out[1] & ~iqentry_stomp[1]),
5700
    iqentry_memready[2] = (iqentry_v[2] & iqentry_memopsvalid[2] & ~iqentry_memissue[2] & ~iqentry_done[2] & ~iqentry_out[2] & ~iqentry_stomp[2]),
5701
    iqentry_memready[3] = (iqentry_v[3] & iqentry_memopsvalid[3] & ~iqentry_memissue[3] & ~iqentry_done[3] & ~iqentry_out[3] & ~iqentry_stomp[3]),
5702
    iqentry_memready[4] = (iqentry_v[4] & iqentry_memopsvalid[4] & ~iqentry_memissue[4] & ~iqentry_done[4] & ~iqentry_out[4] & ~iqentry_stomp[4]),
5703
    iqentry_memready[5] = (iqentry_v[5] & iqentry_memopsvalid[5] & ~iqentry_memissue[5] & ~iqentry_done[5] & ~iqentry_out[5] & ~iqentry_stomp[5]),
5704
    iqentry_memready[6] = (iqentry_v[6] & iqentry_memopsvalid[6] & ~iqentry_memissue[6] & ~iqentry_done[6] & ~iqentry_out[6] & ~iqentry_stomp[6]),
5705
    iqentry_memready[7] = (iqentry_v[7] & iqentry_memopsvalid[7] & ~iqentry_memissue[7] & ~iqentry_done[7] & ~iqentry_out[7] & ~iqentry_stomp[7]);
5706
 
5707 50 robfinch
assign outstanding_stores = (dram0 && dram0_store) ||
5708
                            (dram1 && dram1_store) ||
5709
                            (dram2 && dram2_store);
5710 48 robfinch
 
5711
//
5712
// additional COMMIT logic
5713
//
5714
always @*
5715
begin
5716
    commit0_v <= ({iqentry_v[head0], iqentry_cmt[head0]} == 2'b11 && ~|panic);
5717
    commit0_id <= {iqentry_mem[head0], head0};  // if a memory op, it has a DRAM-bus id
5718
    commit0_tgt <= iqentry_tgt[head0];
5719
    commit0_we  <= iqentry_we[head0];
5720
    commit0_bus <= iqentry_res[head0];
5721 49 robfinch
    if (`NUM_CMT > 1) begin
5722
            commit1_v <= ({iqentry_v[head0], iqentry_cmt[head0]} != 2'b10
5723
                       && {iqentry_v[head1], iqentry_cmt[head1]} == 2'b11
5724
                       && ~|panic);
5725
            commit1_id <= {iqentry_mem[head1], head1};
5726
            commit1_tgt <= iqentry_tgt[head1];
5727
            commit1_we  <= iqentry_we[head1];
5728
            commit1_bus <= iqentry_res[head1];
5729
        end
5730
        else begin
5731
                commit1_tgt <= 12'h000;
5732
                commit1_we <= 8'h00;
5733
        end
5734 48 robfinch
end
5735
 
5736
assign int_commit = (commit0_v && IsIrq(iqentry_instr[head0])) ||
5737 49 robfinch
                    (commit0_v && commit1_v && IsIrq(iqentry_instr[head1]) && `NUM_CMT > 1);
5738 48 robfinch
 
5739
// Detect if a given register will become valid during the current cycle.
5740
// We want a signal that is active during the current clock cycle for the read
5741
// through register file, which trims a cycle off register access for every
5742
// instruction. But two different kinds of assignment statements can't be
5743
// placed under the same always block, it's a bad practice and may not work.
5744
// So a signal is created here with it's own always block.
5745
reg [AREGS-1:0] regIsValid;
5746
always @*
5747
begin
5748
        for (n = 1; n < AREGS; n = n + 1)
5749
        begin
5750
                regIsValid[n] = rf_v[n];
5751
                if (branchmiss)
5752
               if (~livetarget[n]) begin
5753
                        if (branchmiss_thrd) begin
5754
                                if (n >= 128)
5755
                                        regIsValid[n] = `VAL;
5756
                        end
5757
                        else begin
5758
                                if (n < 128)
5759
                                        regIsValid[n] = `VAL;
5760
                        end
5761
               end
5762
                if (commit0_v && n=={commit0_tgt[7:0]})
5763
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit0_tgt[7:0]} ] == commit0_id
5764
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit0_id[`QBITS]] && iqentry_source[ commit0_id[`QBITS] ]));
5765 49 robfinch
                if (commit1_v && n=={commit1_tgt[7:0]} && `NUM_CMT > 1)
5766 48 robfinch
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit1_tgt[7:0]} ] == commit1_id
5767
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit0_id[`QBITS]] && iqentry_source[ commit1_id[`QBITS] ]));
5768
        end
5769
        regIsValid[0] = `VAL;
5770
end
5771
 
5772
// Wait until the cycle after Ra becomes valid to give time to read
5773
// the vector element from the register file.
5774
reg rf_vra0, rf_vra1;
5775
/*always @(posedge clk)
5776
    rf_vra0 <= regIsValid[Ra0s];
5777
always @(posedge clk)
5778
    rf_vra1 <= regIsValid[Ra1s];
5779
*/
5780
// Check how many instructions can be queued. This might be fewer than the
5781
// number ready to queue from the fetch stage if queue slots aren't
5782
// available or if there are no more physical registers left for remapping.
5783
// The fetch stage needs to know how many instructions will queue so this
5784
// logic is placed here.
5785
// NOPs are filtered out and do not enter the instruction queue. The core
5786
// will stream NOPs on a cache miss and they would mess up the queue order
5787
// if there are immediate prefixes in the queue.
5788
// For the VEX instruction, the instruction can't queue until register Ra
5789
// is valid, because register Ra is used to specify the vector element to
5790
// read.
5791
wire q2open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV;
5792
wire q3open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV && iqentry_v[idp1(tail1)]==`INV;
5793
always @*
5794
begin
5795
        canq1 <= FALSE;
5796
        canq2 <= FALSE;
5797
        queued1 <= FALSE;
5798
        queued2 <= FALSE;
5799
        queuedNop <= FALSE;
5800
        vqueued2 <= FALSE;
5801
        if (!branchmiss) begin
5802
      // Two available
5803
      if (fetchbuf1_v & fetchbuf0_v) begin
5804
          // Is there a pair of NOPs ? (cache miss)
5805
          if ((fetchbuf0_instr[`INSTRUCTION_OP]==`NOP) && (fetchbuf1_instr[`INSTRUCTION_OP]==`NOP))
5806
              queuedNop <= TRUE;
5807
          else begin
5808
              // If it's a predicted branch queue only the first instruction, the second
5809
              // instruction will be stomped on.
5810
              if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
5811
                  if (iqentry_v[tail0]==`INV) begin
5812
                      canq1 <= TRUE;
5813
                      queued1 <= TRUE;
5814
                  end
5815
              end
5816
              // This is where a single NOP is allowed through to simplify the code. A
5817
              // single NOP can't be a cache miss. Otherwise it would be necessary to queue
5818
              // fetchbuf1 on tail0 it would add a nightmare to the enqueue code.
5819
              // Not a branch and there are two instructions fetched, see whether or not
5820
              // both instructions can be queued.
5821
              else begin
5822
                  if (iqentry_v[tail0]==`INV) begin
5823
                      canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5824
                      queued1 <= (
5825
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5826
                      if (iqentry_v[tail1]==`INV) begin
5827
                          canq2 <= ((!IsVex(fetchbuf1_instr) || rf_vra1)) || !SUP_VECTOR;
5828
                          queued2 <= (
5829
                                (!IsVector(fetchbuf1_instr) && (!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5830
                          vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5831
                      end
5832
                  end
5833
                  // If an irq is active during a vector instruction fetch, claim the vector instruction
5834
                  // is finished queueing even though it may not be. It'll pick up where it left off after
5835
                  // the exception is processed.
5836
                  if (hirq) begin
5837
                        if (IsVector(fetchbuf0_instr) && IsVector(fetchbuf1_instr) && vechain) begin
5838
                                queued1 <= TRUE;
5839
                                queued2 <= TRUE;
5840
                        end
5841
                        else if (IsVector(fetchbuf0_instr)) begin
5842
                                queued1 <= TRUE;
5843
                                if (vqe0 < vl-2)
5844
                                        queued2 <= TRUE;
5845
                                else
5846
                                        queued2 <= iqentry_v[tail1]==`INV;
5847
                        end
5848
                  end
5849
              end
5850
          end
5851
      end
5852
      // One available
5853
      else if (fetchbuf0_v) begin
5854
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
5855
              if (iqentry_v[tail0]==`INV) begin
5856
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5857
                  queued1 <=
5858
                        (((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5859
              end
5860
              if (iqentry_v[tail1]==`INV) begin
5861
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
5862
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5863
                end
5864
                if (hirq) begin
5865
                if (IsVector(fetchbuf0_instr)) begin
5866
                        queued1 <= TRUE;
5867
                        if (vqe0 < vl-2)
5868
                                queued2 <= iqentry_v[tail1]==`INV;
5869
                end
5870
                end
5871
          end
5872
          else
5873
              queuedNop <= TRUE;
5874
      end
5875
      else if (fetchbuf1_v) begin
5876
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
5877
              if (iqentry_v[tail0]==`INV) begin
5878
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
5879
                  queued1 <= (
5880
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
5881
              end
5882
              if (iqentry_v[tail1]==`INV) begin
5883
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
5884
                  vqueued2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2;
5885
                end
5886
                if (hirq) begin
5887
                if (IsVector(fetchbuf1_instr)) begin
5888
                        queued1 <= TRUE;
5889
                        if (vqe1 < vl-2)
5890
                                queued2 <= iqentry_v[tail1]==`INV;
5891
                end
5892
                end
5893
          end
5894
          else
5895
              queuedNop <= TRUE;
5896
      end
5897
      //else no instructions available to queue
5898
    end
5899
    else begin
5900
      // One available
5901
      if (fetchbuf0_v && fetchbuf0_thrd != branchmiss_thrd) begin
5902
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
5903
              if (iqentry_v[tail0]==`INV) begin
5904
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5905
                  queued1 <= (
5906
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5907
              end
5908
              if (iqentry_v[tail1]==`INV) begin
5909
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
5910
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5911
                end
5912
          end
5913
          else
5914
              queuedNop <= TRUE;
5915
      end
5916
      else if (fetchbuf1_v && fetchbuf1_thrd != branchmiss_thrd) begin
5917
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
5918
              if (iqentry_v[tail0]==`INV) begin
5919
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
5920
                  queued1 <= (
5921
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
5922
              end
5923
              if (iqentry_v[tail1]==`INV) begin
5924
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
5925
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5926
                end
5927
          end
5928
          else
5929
              queuedNop <= TRUE;
5930
      end
5931
        else
5932
                queuedNop <= TRUE;
5933
    end
5934
end
5935
 
5936
//
5937
// Branchmiss seems to be sticky sometimes during simulation. For instance branch miss
5938
// and cache miss at same time. The branchmiss should clear before the core continues
5939
// so the positive edge is detected to avoid incrementing the sequnce number too many
5940
// times.
5941
wire pebm;
5942
edge_det uedbm (.rst(rst), .clk(clk), .ce(1'b1), .i(branchmiss), .pe(pebm), .ne(), .ee() );
5943
 
5944
reg [5:0] ld_time;
5945
reg [63:0] wc_time_dat;
5946
reg [63:0] wc_times;
5947
always @(posedge tm_clk_i)
5948
begin
5949
        if (|ld_time)
5950
                wc_time <= wc_time_dat;
5951
        else begin
5952
                wc_time[31:0] <= wc_time[31:0] + 32'd1;
5953
                if (wc_time[31:0] >= TM_CLKFREQ-1) begin
5954
                        wc_time[31:0] <= 32'd0;
5955
                        wc_time[63:32] <= wc_time[63:32] + 32'd1;
5956
                end
5957
        end
5958
end
5959
 
5960
 
5961
// Monster clock domain.
5962
// Like to move some of this to clocking under different always blocks in order
5963
// to help out the toolset's synthesis, but it ain't gonna be easy.
5964
// Simulation doesn't like it if things are under separate always blocks.
5965
// Synthesis doesn't like it if things are under the same always block.
5966
 
5967 49 robfinch
//always @(posedge clk)
5968
//begin
5969
//      branchmiss <= excmiss|fcu_branchmiss;
5970
//    misspc <= excmiss ? excmisspc : fcu_misspc;
5971
//    missid <= excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
5972
//      branchmiss_thrd <=  excmiss ? excthrd : fcu_thrd;
5973
//end
5974 48 robfinch
 
5975
always @(posedge clk)
5976
if (rst) begin
5977
`ifdef SUPPORT_SMT
5978
     mstatus[0] <= 64'h0007;     // select register set #0 for thread 0
5979
     mstatus[1] <= 64'h8007;    // select register set #2 for thread 1
5980
`else
5981
     mstatus <= 64'h0007;       // select register set #0 for thread 0
5982
`endif
5983
    for (n = 0; n < QENTRIES; n = n + 1) begin
5984
         iqentry_v[n] <= `INV;
5985
         iqentry_iv[n] <= `INV;
5986
         iqentry_is[n] <= 3'b00;
5987
         iqentry_done[n] <= FALSE;
5988
         iqentry_cmt[n] <= FALSE;
5989
         iqentry_out[n] <= FALSE;
5990
         iqentry_agen[n] <= FALSE;
5991
         iqentry_sn[n] <= 32'd0;
5992
         iqentry_pt[n] <= FALSE;
5993
         iqentry_bt[n] <= FALSE;
5994
         iqentry_br[n] <= FALSE;
5995
         iqentry_aq[n] <= FALSE;
5996
         iqentry_rl[n] <= FALSE;
5997
         iqentry_alu0[n] <= FALSE;
5998
         iqentry_alu[n] <= FALSE;
5999
         iqentry_alu0_issue[n] <= FALSE;
6000
         iqentry_alu1_issue[n] <= FALSE;
6001
         iqentry_fpu[n] <= FALSE;
6002 49 robfinch
         iqentry_fpu1_issue[n] <= FALSE;
6003
         iqentry_fpu2_issue[n] <= FALSE;
6004 48 robfinch
         iqentry_fsync[n] <= FALSE;
6005
         iqentry_fc[n] <= FALSE;
6006
         iqentry_fcu_issue[n] <= FALSE;
6007
         iqentry_jmp[n] <= FALSE;
6008
         iqentry_ldcmp[n] <= FALSE;
6009
         iqentry_load[n] <= FALSE;
6010
         iqentry_rtop[n] <= FALSE;
6011
         iqentry_sei[n] <= FALSE;
6012
         iqentry_shft48[n] <= FALSE;
6013
         iqentry_sync[n] <= FALSE;
6014
         iqentry_ven[n] <= 6'd0;
6015
         iqentry_vl[n] <= 8'd0;
6016
         iqentry_we[n] <= 8'h00;
6017
         iqentry_rfw[n] <= FALSE;
6018
         iqentry_rmw[n] <= FALSE;
6019
         iqentry_pc[n] <= RSTPC;
6020
         iqentry_instr[n] <= `NOP_INSN;
6021
         iqentry_insln[n] <= 4'd4;
6022
         iqentry_preload[n] <= FALSE;
6023
         iqentry_mem[n] <= FALSE;
6024
         iqentry_memndx[n] <= FALSE;
6025
         iqentry_memissue[n] <= FALSE;
6026
         iqentry_mem_islot[n] <= 3'd0;
6027 49 robfinch
         iqentry_memdb[n] <= FALSE;
6028
         iqentry_memsb[n] <= FALSE;
6029 48 robfinch
         iqentry_tgt[n] <= 6'd0;
6030
         iqentry_imm[n] <= 1'b0;
6031
         iqentry_a0[n] <= 64'd0;
6032
         iqentry_a1[n] <= 64'd0;
6033
         iqentry_a2[n] <= 64'd0;
6034
         iqentry_a3[n] <= 64'd0;
6035
         iqentry_a1_v[n] <= `INV;
6036
         iqentry_a2_v[n] <= `INV;
6037
         iqentry_a3_v[n] <= `INV;
6038
         iqentry_a1_s[n] <= 5'd0;
6039
         iqentry_a2_s[n] <= 5'd0;
6040
         iqentry_a3_s[n] <= 5'd0;
6041
         iqentry_canex[n] <= FALSE;
6042
    end
6043 49 robfinch
     bwhich <= 2'b00;
6044 48 robfinch
     dram0 <= `DRAMSLOT_AVAIL;
6045
     dram1 <= `DRAMSLOT_AVAIL;
6046
     dram2 <= `DRAMSLOT_AVAIL;
6047
     dram0_instr <= `NOP_INSN;
6048
     dram1_instr <= `NOP_INSN;
6049
     dram2_instr <= `NOP_INSN;
6050
     dram0_addr <= 32'h0;
6051
     dram1_addr <= 32'h0;
6052
     dram2_addr <= 32'h0;
6053
     L1_adr <= RSTPC;
6054
     invic <= FALSE;
6055
     tail0 <= 3'd0;
6056
     tail1 <= 3'd1;
6057
     head0 <= 0;
6058
     head1 <= 1;
6059
     head2 <= 2;
6060
     head3 <= 3;
6061
     head4 <= 4;
6062
     head5 <= 5;
6063
     head6 <= 6;
6064
     head7 <= 7;
6065
     panic = `PANIC_NONE;
6066
     alu0_dataready <= 0;
6067
     alu1_dataready <= 0;
6068
     alu0_sourceid <= 5'd0;
6069
     alu1_sourceid <= 5'd0;
6070
`ifdef SIM
6071
                alu0_pc <= RSTPC;
6072
                alu0_instr <= `NOP_INSN;
6073
                alu0_argA <= 64'h0;
6074
                alu0_argB <= 64'h0;
6075
                alu0_argC <= 64'h0;
6076
                alu0_argI <= 64'h0;
6077
                alu0_bt <= 1'b0;
6078
                alu0_mem <= 1'b0;
6079
                alu0_shft48 <= 1'b0;
6080
                alu0_thrd <= 1'b0;
6081
                alu0_tgt <= 6'h00;
6082
                alu0_ven <= 6'd0;
6083
                alu1_pc <= RSTPC;
6084
                alu1_instr <= `NOP_INSN;
6085
                alu1_argA <= 64'h0;
6086
                alu1_argB <= 64'h0;
6087
                alu1_argC <= 64'h0;
6088
                alu1_argI <= 64'h0;
6089
                alu1_bt <= 1'b0;
6090
                alu1_mem <= 1'b0;
6091
                alu1_shft48 <= 1'b0;
6092
                alu1_thrd <= 1'b0;
6093
                alu1_tgt <= 6'h00;
6094
                alu1_ven <= 6'd0;
6095
`endif
6096
     fcu_dataready <= 0;
6097
     fcu_instr <= `NOP_INSN;
6098
     fcu_retadr_v <= 0;
6099
     dramA_v <= 0;
6100
     dramB_v <= 0;
6101
     dramC_v <= 0;
6102
     I <= 0;
6103
     icstate <= IDLE;
6104
     bstate <= BIDLE;
6105
     tick <= 64'd0;
6106
     bte_o <= 2'b00;
6107
     cti_o <= 3'b000;
6108
     cyc_o <= `LOW;
6109
     stb_o <= `LOW;
6110
     we_o <= `LOW;
6111
     sel_o <= 8'h00;
6112
     sr_o <= `LOW;
6113
     cr_o <= `LOW;
6114
     adr_o <= RSTPC;
6115
     icl_o <= `LOW;             // instruction cache load
6116
     cr0 <= 64'd0;
6117
     cr0[13:8] <= 6'd0;         // select register set #0
6118
     cr0[30] <= TRUE;           // enable data caching
6119
     cr0[32] <= TRUE;           // enable branch predictor
6120
     cr0[16] <= 1'b0;           // disable SMT
6121
     cr0[17] <= 1'b0;           // sequence number reset = 1
6122
     pcr <= 32'd0;
6123
     pcr2 <= 64'd0;
6124
    for (n = 0; n < PREGS; n = n + 1)
6125
         rf_v[n] <= `VAL;
6126
     tgtq <= FALSE;
6127 49 robfinch
     fp1_rm <= 3'd0;                    // round nearest even - default rounding mode
6128
     fp2_rm <= 3'd0;
6129 48 robfinch
     waitctr <= 64'd0;
6130
    for (n = 0; n < 16; n = n + 1)
6131
         badaddr[n] <= 64'd0;
6132
     sbl <= 32'h0;
6133
     sbu <= 32'hFFFFFFFF;
6134
    // Vector
6135
     vqe0 <= 6'd0;
6136
     vqet0 <= 6'd0;
6137
     vqe1 <= 6'd0;
6138
     vqet1 <= 6'd0;
6139
     vl <= 7'd62;
6140
    for (n = 0; n < 8; n = n + 1)
6141
         vm[n] <= 64'h7FFFFFFFFFFFFFFF;
6142
     nop_fetchbuf <= 4'h0;
6143
     seq_num <= 5'd0;
6144
     seq_num1 <= 5'd0;
6145
     fcu_done <= `TRUE;
6146
     sema <= 64'h0;
6147
     tvec[0] <= RSTPC;
6148 49 robfinch
     pmr <= 64'hFFFFFFFFFFFFFFFF;
6149
     pmr[0] <= `ID1_AVAIL;
6150
     pmr[1] <= `ID2_AVAIL;
6151
     pmr[2] <= `ID3_AVAIL;
6152
     pmr[8] <= `ALU0_AVAIL;
6153
     pmr[9] <= `ALU1_AVAIL;
6154
     pmr[16] <= `FPU1_AVAIL;
6155
     pmr[17] <= `FPU2_AVAIL;
6156
     pmr[24] <= `MEM1_AVAIL;
6157
     pmr[25] <= `MEM2_AVAIL;
6158
                 pmr[26] <= `MEM3_AVAIL;
6159
     pmr[32] <= `FCU_AVAIL;
6160
     for (n = 0; n < `WB_DEPTH; n = n + 1) begin
6161
        wb_v[n] <= 1'b0;
6162
        wb_rmw[n] <= 1'b0;
6163
        wb_id[n] <= {QENTRIES{1'b0}};
6164
     end
6165
     wb_en <= `TRUE;
6166
     wbo_id <= {QENTRIES{1'b0}};
6167
`ifdef SIM
6168
                wb_merges <= 32'd0;
6169
`endif
6170 48 robfinch
end
6171
else begin
6172 49 robfinch
        if (|fb_panic)
6173
                panic <= fb_panic;
6174
        begin
6175
                branchmiss <= excmiss|fcu_branchmiss;
6176
            misspc <= excmiss ? excmisspc : fcu_misspc;
6177
            missid <= excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
6178
                branchmiss_thrd <=  excmiss ? excthrd : fcu_thrd;
6179
        end
6180 48 robfinch
        // The following signals only pulse
6181
 
6182
        // Instruction decode output should only pulse once for a queue entry. We
6183
        // want the decode to be invalidated after a clock cycle so that it isn't
6184
        // inadvertently used to update the queue at a later point.
6185
        id1_vi <= `INV;
6186 49 robfinch
        if (`NUM_IDU > 1)
6187
                id2_vi <= `INV;
6188
        if (`NUM_IDU > 2)
6189
                id3_vi <= `INV;
6190
        if (iqentry_v[nid] && iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]])
6191
                fcu_dataready <= `INV;
6192 48 robfinch
        ld_time <= {ld_time[4:0],1'b0};
6193
        wc_times <= wc_time;
6194
     rf_vra0 <= regIsValid[Ra0s];
6195
     rf_vra1 <= regIsValid[Ra1s];
6196
    if (vqe0 >= vl) begin
6197
         vqe0 <= 6'd0;
6198
         vqet0 <= 6'h0;
6199
    end
6200
    if (vqe1 >= vl) begin
6201
         vqe1 <= 6'd0;
6202
         vqet1 <= 6'h0;
6203
    end
6204
    // Turn off vector chaining indicator when chained instructions are done.
6205
    if ((vqe0 >= vl || vqe0==6'd0) && (vqe1 >= vl || vqe1==6'd0))
6206
`ifdef SUPPORT_SMT
6207
        mstatus[0][32] <= 1'b0;
6208
`else
6209
        mstatus[32] <= 1'b0;
6210
`endif
6211
 
6212
     nop_fetchbuf <= 4'h0;
6213
     excmiss <= FALSE;
6214
     invic <= FALSE;
6215
     tick <= tick + 64'd1;
6216
     alu0_ld <= FALSE;
6217
     alu1_ld <= FALSE;
6218 49 robfinch
     fpu1_ld <= FALSE;
6219
     fpu2_ld <= FALSE;
6220 48 robfinch
     fcu_ld <= FALSE;
6221
     fcu_retadr_v <= FALSE;
6222
     dramA_v <= FALSE;
6223
     dramB_v <= FALSE;
6224
     dramC_v <= FALSE;
6225
     cr0[17] <= 1'b0;
6226
    if (waitctr != 64'd0)
6227
         waitctr <= waitctr - 64'd1;
6228
 
6229
 
6230 50 robfinch
    if (iqentry_fc[fcu_id[`QBITS]] && iqentry_v[fcu_id[`QBITS]] && !iqentry_done[fcu_id[`QBITS]] && iqentry_out[fcu_id[`QBITS]])
6231 48 robfinch
        fcu_timeout <= fcu_timeout + 8'd1;
6232
 
6233
        if (branchmiss) begin
6234
        for (n = 1; n < PREGS; n = n + 1)
6235
           if (~livetarget[n]) begin
6236
                        if (branchmiss_thrd) begin
6237
                                if (n >= 128)
6238
                                rf_v[n] <= `VAL;
6239
                        end
6240
                        else begin
6241
                                if (n < 128)
6242
                                rf_v[n] <= `VAL;
6243
                end
6244
           end
6245
 
6246
            if (|iqentry_0_latestID)     if (iqentry_thrd[0]==branchmiss_thrd) rf_source[ {iqentry_tgt[0][7:0]} ] <= { 1'b0, iqentry_mem[0], 3'd0 };
6247
        if (|iqentry_1_latestID)     if (iqentry_thrd[1]==branchmiss_thrd) rf_source[ {iqentry_tgt[1][7:0]} ] <= { 1'b0, iqentry_mem[1], 3'd1 };
6248
        if (|iqentry_2_latestID)     if (iqentry_thrd[2]==branchmiss_thrd) rf_source[ {iqentry_tgt[2][7:0]} ] <= { 1'b0, iqentry_mem[2], 3'd2 };
6249
        if (|iqentry_3_latestID)     if (iqentry_thrd[3]==branchmiss_thrd) rf_source[ {iqentry_tgt[3][7:0]} ] <= { 1'b0, iqentry_mem[3], 3'd3 };
6250
        if (|iqentry_4_latestID)     if (iqentry_thrd[4]==branchmiss_thrd) rf_source[ {iqentry_tgt[4][7:0]} ] <= { 1'b0, iqentry_mem[4], 3'd4 };
6251
        if (|iqentry_5_latestID)     if (iqentry_thrd[5]==branchmiss_thrd) rf_source[ {iqentry_tgt[5][7:0]} ] <= { 1'b0, iqentry_mem[5], 3'd5 };
6252
        if (|iqentry_6_latestID)     if (iqentry_thrd[6]==branchmiss_thrd) rf_source[ {iqentry_tgt[6][7:0]} ] <= { 1'b0, iqentry_mem[6], 3'd6 };
6253
        if (|iqentry_7_latestID)     if (iqentry_thrd[7]==branchmiss_thrd) rf_source[ {iqentry_tgt[7][7:0]} ] <= { 1'b0, iqentry_mem[7], 3'd7 };
6254
 
6255
    end
6256
 
6257
    // The source for the register file data might have changed since it was
6258
    // placed on the commit bus. So it's needed to check that the source is
6259
    // still as expected to validate the register.
6260
        if (commit0_v) begin
6261
        if (!rf_v[ {commit0_tgt[7:0]} ])
6262
//             rf_v[ {commit0_tgt[7:0]} ] <= rf_source[ commit0_tgt[7:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]);
6263
             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] ]);
6264
        if (commit0_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit0_tgt, commit0_bus, regIsValid[commit0_tgt[5:0]],
6265
        rf_source[ {commit0_tgt[7:0]} ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]));
6266
        if (commit0_tgt[5:0]==6'd30 && commit0_bus==64'd0)
6267
                $display("FP <= 0");
6268
    end
6269 49 robfinch
    if (commit1_v && `NUM_CMT > 1) begin
6270 48 robfinch
        if (!rf_v[ {commit1_tgt[7:0]} ]) begin
6271
                if ({commit1_tgt[7:0]}=={commit0_tgt[7:0]})
6272
                         rf_v[ {commit1_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}];
6273
                        /*
6274
                                (rf_source[ commit0_tgt[4:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ])) ||
6275
                                (rf_source[ commit1_tgt[4:0] ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
6276
                        */
6277
                else
6278
                 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] ]);
6279
        end
6280
        if (commit1_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit1_tgt, commit1_bus, regIsValid[commit1_tgt[5:0]],
6281
        rf_source[ {commit1_tgt[7:0]} ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
6282
        if (commit1_tgt[5:0]==6'd30 && commit1_bus==64'd0)
6283
                $display("FP <= 0");
6284
    end
6285
     rf_v[0] <= 1;
6286
 
6287 49 robfinch
  //
6288
  // ENQUEUE
6289
  //
6290
  // place up to two instructions from the fetch buffer into slots in the IQ.
6291
  //   note: they are placed in-order, and they are expected to be executed
6292
  // 0, 1, or 2 of the fetch buffers may have valid data
6293
  // 0, 1, or 2 slots in the instruction queue may be available.
6294
  // if we notice that one of the instructions in the fetch buffer is a predicted branch,
6295
  // (set branchback/backpc and delete any instructions after it in fetchbuf)
6296
  //
6297 48 robfinch
 
6298
        // enqueue fetchbuf0 and fetchbuf1, but only if there is room, 
6299
        // and ignore fetchbuf1 if fetchbuf0 has a backwards branch in it.
6300
        //
6301
        // also, do some instruction-decode ... set the operand_valid bits in the IQ
6302
        // appropriately so that the DATAINCOMING stage does not have to look at the opcode
6303
        //
6304
        if (!branchmiss)        // don't bother doing anything if there's been a branch miss
6305
 
6306
                case ({fetchbuf0_v, fetchbuf1_v})
6307
 
6308
            2'b00: ; // do nothing
6309
 
6310
            2'b01:
6311
                    if (canq1) begin
6312
                    if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
6313
                         vqe1 <= vqe1 + 4'd1;
6314
                        if (IsVCmprss(fetchbuf1_instr)) begin
6315
                            if (vm[fetchbuf1_instr[25:23]][vqe1])
6316
                                 vqet1 <= vqet1 + 4'd1;
6317
                        end
6318
                        else
6319
                             vqet1 <= vqet1 + 4'd1;
6320
                        if (vqe1 >= vl-2)
6321
                                 nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
6322
                            enque1(tail0, fetchbuf1_thrd ? seq_num1 : seq_num, vqe1);
6323
                            if (fetchbuf1_thrd)
6324
                                seq_num1 <= seq_num1 + 5'd1;
6325
                            else
6326
                                seq_num <= seq_num + 5'd1;
6327
                             tgtq <= FALSE;
6328
                            if (fetchbuf1_rfw) begin
6329
                                 rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_memld, tail0 }; // top bit indicates ALU/MEM bus
6330
                                 rf_v [Rt1s] <= `INV;
6331
                            end
6332
                        if (canq2 && vqe1 < vl-2) begin
6333
                                 vqe1 <= vqe1 + 4'd2;
6334
                                if (IsVCmprss(fetchbuf1_instr)) begin
6335
                                    if (vm[fetchbuf1_instr[25:23]][vqe1+6'd1])
6336
                                         vqet1 <= vqet1 + 4'd2;
6337
                                end
6338
                                else
6339
                                     vqet1 <= vqet1 + 4'd2;
6340
                                    enque1(tail1, fetchbuf1_thrd ? seq_num1 + 5'd1 : seq_num + 5'd1, vqe1 + 6'd1);
6341
                                    if (fetchbuf1_thrd)
6342
                                        seq_num1 <= seq_num1 + 5'd2;
6343
                                    else
6344
                                        seq_num <= seq_num + 5'd2;
6345
                                     tgtq <= FALSE;
6346
                                    if (fetchbuf1_rfw) begin
6347
                                         rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_memld, tail1 }; // top bit indicates ALU/MEM bus
6348
                                         rf_v [Rt1s] <= `INV;
6349
                                    end
6350
                        end
6351
                    end
6352
                    else begin
6353
                            enque1(tail0, fetchbuf1_thrd ? seq_num1 : seq_num, 6'd0);
6354
                            if (fetchbuf1_thrd)
6355
                                seq_num1 <= seq_num1 + 5'd1;
6356
                            else
6357
                                seq_num <= seq_num + 5'd1;
6358
                             tgtq <= FALSE;
6359
                            if (fetchbuf1_rfw) begin
6360
                                 rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_memld, tail0 }; // top bit indicates ALU/MEM bus
6361
                                 rf_v [Rt1s] <= `INV;
6362
                            end
6363
                        end
6364
                    end
6365
 
6366
            2'b10:
6367
                if (canq1) begin
6368
//                  $display("queued1: %d", queued1);
6369
//                      if (!IsBranch(fetchbuf0_instr))         panic <= `PANIC_FETCHBUFBEQ;
6370
//                      if (!predict_taken0)    panic <= `PANIC_FETCHBUFBEQ;
6371
                        //
6372
                        // this should only happen when the first instruction is a BEQ-backwards and the IQ
6373
                        // happened to be full on the previous cycle (thus we deleted fetchbuf1 but did not
6374
                        // enqueue fetchbuf0) ... probably no need to check for LW -- sanity check, just in case
6375
                        //
6376
                    if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
6377
                         vqe0 <= vqe0 + 4'd1;
6378
                        if (IsVCmprss(fetchbuf0_instr)) begin
6379
                            if (vm[fetchbuf0_instr[25:23]][vqe0])
6380
                                 vqet0 <= vqet0 + 4'd1;
6381
                        end
6382
                        else
6383
                             vqet0 <= vqet0 + 4'd1;
6384
                        if (vqe0 >= vl-2)
6385
                                 nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6386
                                enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, vqe0);
6387
                                if (fetchbuf0_thrd)
6388
                                        seq_num1 <= seq_num1 + 5'd1;
6389
                                else
6390
                                        seq_num <= seq_num + 5'd1;
6391
                             tgtq <= FALSE;
6392
                                if (fetchbuf0_rfw) begin
6393
                                 rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail0 };    // top bit indicates ALU/MEM bus
6394
                                 rf_v[Rt0s] <= `INV;
6395
                            end
6396
                        if (canq2) begin
6397
                                    if (vqe0 < vl-2) begin
6398
                                         vqe0 <= vqe0 + 4'd2;
6399
                                        if (IsVCmprss(fetchbuf0_instr)) begin
6400
                                            if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
6401
                                                 vqet0 <= vqet0 + 4'd2;
6402
                                        end
6403
                                        else
6404
                                             vqet0 <= vqet0 + 4'd2;
6405
                                                enque0(tail1, fetchbuf0_thrd ? seq_num1 + 5'd1 : seq_num+5'd1, vqe0 + 6'd1);
6406
                                                if (fetchbuf0_thrd)
6407
                                                        seq_num1 <= seq_num1 + 5'd2;
6408
                                                else
6409
                                                        seq_num <= seq_num + 5'd2;
6410
                                             tgtq <= FALSE;
6411
                                                if (fetchbuf0_rfw) begin
6412
                                                 rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail1 };    // top bit indicates ALU/MEM bus
6413
                                                 rf_v[Rt0s] <= `INV;
6414
                                            end
6415
                                    end
6416
                        end
6417
                    end
6418
                    else begin
6419
                                enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, 6'd0);
6420
                                if (fetchbuf0_thrd)
6421
                                        seq_num1 <= seq_num1 + 5'd1;
6422
                                else
6423
                                        seq_num <= seq_num + 5'd1;
6424
                             tgtq <= FALSE;
6425
                                if (fetchbuf0_rfw) begin
6426
                                 rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail0 };    // top bit indicates ALU/MEM bus
6427
                                 rf_v[Rt0s] <= `INV;
6428
                            end
6429
                        end
6430
                    end
6431
 
6432
            2'b11:
6433
                    if (canq1) begin
6434
                                //
6435
                                // if the first instruction is a predicted branch, enqueue it & stomp on all following instructions
6436
                                // but only if the following instruction is in the same thread. Otherwise we want to queue two.
6437
                                //
6438
                                if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
6439
                             tgtq <= FALSE;
6440
                            enque0(tail0,fetchbuf0_thrd ? seq_num1 : seq_num,6'd0);
6441
                                if (fetchbuf0_thrd)
6442
                                        seq_num1 <= seq_num1 + 5'd1;
6443
                                else
6444
                                        seq_num <= seq_num + 5'd1;
6445
                                        if (fetchbuf0_rfw) begin
6446
                                             rf_source[ Rt0s ] <= {1'b0,fetchbuf0_memld, tail0};
6447
                                             rf_v [ Rt0s ] <= `INV;
6448
                                        end
6449
                                end
6450
 
6451
                                else begin      // fetchbuf0 doesn't contain a predicted branch
6452
                                    //
6453
                                    // so -- we can enqueue 1 or 2 instructions, depending on space in the IQ
6454
                                    // update the rf_v and rf_source bits separately (at end)
6455
                                    //   the problem is that if we do have two instructions, 
6456
                                    //   they may interact with each other, so we have to be
6457
                                    //   careful about where things point.
6458
                                    //
6459
                                    // enqueue the first instruction ...
6460
                                    //
6461
                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
6462
                                 vqe0 <= vqe0 + 4'd1;
6463
                                if (IsVCmprss(fetchbuf0_instr)) begin
6464
                                    if (vm[fetchbuf0_instr[25:23]][vqe0])
6465
                                         vqet0 <= vqet0 + 4'd1;
6466
                                end
6467
                                else
6468
                                     vqet0 <= vqet0 + 4'd1;
6469
                                if (vqe0 >= vl-2)
6470
                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6471
                            end
6472
                            tgtq <= FALSE;
6473
                            if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
6474
                                    enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, vqe0);
6475
                                        if (fetchbuf0_thrd)
6476
                                                seq_num1 <= seq_num1 + 5'd1;
6477
                                        else
6478
                                                seq_num <= seq_num + 5'd1;
6479
                                            //
6480
                                            // if there is room for a second instruction, enqueue it
6481
                                            //
6482
                                            if (canq2) begin
6483
                                                if (vechain && IsVector(fetchbuf1_instr)
6484
                                                && Ra1s != Rt0s // And there is no dependency
6485
                                                && Rb1s != Rt0s
6486
                                                && Rc1s != Rt0s
6487
                                                ) begin
6488
`ifdef SUPPORT_SMT
6489
                                                        mstatus[0][32] <= 1'b1;
6490
`else
6491
                                                        mstatus[32] <= 1'b1;
6492
`endif
6493
                                                vqe1 <= vqe1 + 4'd1;
6494
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6495
                                                    if (vm[fetchbuf1_instr[25:23]][vqe1])
6496
                                                         vqet1 <= vqet1 + 4'd1;
6497
                                                end
6498
                                                else
6499
                                                     vqet1 <= vqet1 + 4'd1;
6500
                                                if (vqe1 >= vl-2)
6501
                                                        nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
6502
                                                        enque1(tail1,
6503
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6504
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6505
                                                                fetchbuf1_thrd ? seq_num1 + 5'd1: seq_num + 5'd1, 6'd0);
6506
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6507
                                                                if (fetchbuf1_thrd)
6508
                                                                        seq_num1 <= seq_num1 + 5'd2;
6509
                                                                else
6510
                                                                        seq_num <= seq_num + 5'd2;
6511
                                                        end
6512
                                                        else begin
6513
                                                                if (fetchbuf1_thrd)
6514
                                                                        seq_num1 <= seq_num1 + 5'd1;
6515
                                                                else
6516
                                                                        seq_num <= seq_num + 5'd1;
6517
                                                        end
6518
 
6519
                                                                // SOURCE 1 ...
6520
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6521
                                                                if (~fetchbuf0_rfw) begin
6522
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6523
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6524
                                                                end
6525
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6526
                                                                else if (Ra1 == Rt0) begin
6527
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6528
                                                                     iqentry_a1_v [tail1] <= `INV;
6529
                                                                     iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6530
                                                                end
6531
                                                                // if no overlap, get info from rf_v and rf_source
6532
                                                                else begin
6533
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6534
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6535
                                                                end
6536
 
6537
                                                                // SOURCE 2 ...
6538
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6539
                                                                if (~fetchbuf0_rfw) begin
6540
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6541
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6542
                                                                end
6543
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6544
                                                                else if (Rb1s == Rt0s) begin
6545
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6546
                                                                     iqentry_a2_v [tail1] <= `INV;
6547
                                                                     iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6548
                                                                end
6549
                                                                // if no overlap, get info from rf_v and rf_source
6550
                                                                else begin
6551
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6552
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6553
                                                                end
6554
 
6555
                                                                // SOURCE 3 ...
6556
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6557
                                                                if (~fetchbuf0_rfw) begin
6558
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6559
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6560
                                                                end
6561
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6562
                                                                else if (Rc1 == Rt0) begin
6563
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6564
                                                                     iqentry_a3_v [tail1] <= `INV;
6565
                                                                     iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6566
                                                                end
6567
                                                                // if no overlap, get info from rf_v and rf_source
6568
                                                                else begin
6569
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6570
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6571
                                                                end
6572
 
6573
                                                                // if the two instructions enqueued target the same register, 
6574
                                                                // make sure only the second writes to rf_v and rf_source.
6575
                                                                // first is allowed to update rf_v and rf_source only if the
6576
                                                                // second has no target
6577
                                                                //
6578
                                                            if (fetchbuf0_rfw) begin
6579
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6580
                                                                     rf_v [ Rt0s] <= `INV;
6581
                                                            end
6582
                                                            if (fetchbuf1_rfw) begin
6583
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6584
                                                                     rf_v [ Rt1s ] <= `INV;
6585
                                                            end
6586
                                                end
6587
                                                // If there was a vector instruction in fetchbuf0, we really
6588
                                                // want to queue the next vector element, not the next
6589
                                                // instruction waiting in fetchbuf1.
6590
                                            else if (IsVector(fetchbuf0_instr) && SUP_VECTOR && vqe0 < vl-1) begin
6591
                                                 vqe0 <= vqe0 + 4'd2;
6592
                                                if (IsVCmprss(fetchbuf0_instr)) begin
6593
                                                    if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
6594
                                                         vqet0 <= vqet0 + 4'd2;
6595
                                                end
6596
                                                else
6597
                                                     vqet0 <= vqet0 + 4'd2;
6598
                                                if (vqe0 >= vl-3)
6599
                                                 nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6600
                                            if (vqe0 < vl-1) begin
6601
                                                                enque0(tail1, fetchbuf0_thrd ? seq_num1 + 5'd1 : seq_num + 5'd1, vqe0 + 6'd1);
6602
                                                                if (fetchbuf0_thrd)
6603
                                                                        seq_num1 <= seq_num1 + 5'd2;
6604
                                                                else
6605
                                                                        seq_num <= seq_num + 5'd2;
6606
 
6607
                                                                        // SOURCE 1 ...
6608
                                                     iqentry_a1_v [tail1] <= regIsValid[Ra0s];
6609
                                                     iqentry_a1_s [tail1] <= rf_source [Ra0s];
6610
 
6611
                                                                        // SOURCE 2 ...
6612
                                                     iqentry_a2_v [tail1] <= regIsValid[Rb0s];
6613
                                                     iqentry_a2_s [tail1] <= rf_source[ Rb0s ];
6614
 
6615
                                                                        // SOURCE 3 ...
6616
                                                     iqentry_a3_v [tail1] <= regIsValid[Rc0s];
6617
                                                     iqentry_a3_s [tail1] <= rf_source[ Rc0s ];
6618
 
6619
                                                                        // if the two instructions enqueued target the same register, 
6620
                                                                        // make sure only the second writes to rf_v and rf_source.
6621
                                                                        // first is allowed to update rf_v and rf_source only if the
6622
                                                                        // second has no target (BEQ or SW)
6623
                                                                        //
6624
                                                                    if (fetchbuf0_rfw) begin
6625
                                                                             rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail1 };
6626
                                                                             rf_v [ Rt0s ] <= `INV;
6627
                                                                    end
6628
                                                                end
6629
                                                end
6630
                                            else if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
6631
                                                 vqe1 <= 6'd1;
6632
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6633
                                                    if (vm[fetchbuf1_instr[25:23]][IsVector(fetchbuf0_instr)? 6'd0:vqe1+6'd1])
6634
                                                         vqet1 <= 6'd1;
6635
                                                else
6636
                                                         vqet1 <= 6'd0;
6637
                                                end
6638
                                                else
6639
                                                         vqet1 <= 6'd1;
6640
                                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR)
6641
                                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6642
                                                        enque1(tail1,
6643
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6644
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6645
                                                                fetchbuf1_thrd ? seq_num1 + 5'd1: seq_num + 5'd1, 6'd0);
6646
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6647
                                                                if (fetchbuf1_thrd)
6648
                                                                        seq_num1 <= seq_num1 + 5'd2;
6649
                                                                else
6650
                                                                        seq_num <= seq_num + 5'd2;
6651
                                                        end
6652
                                                        else begin
6653
                                                                if (fetchbuf1_thrd)
6654
                                                                        seq_num1 <= seq_num1 + 5'd1;
6655
                                                                else
6656
                                                                        seq_num <= seq_num + 5'd1;
6657
                                                        end
6658
 
6659
                                                                // SOURCE 1 ...
6660
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6661
                                                                if (~fetchbuf0_rfw) begin
6662
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6663
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6664
                                                                end
6665
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6666
                                                                else if (Ra1 == Rt0) begin
6667
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6668
                                                                     iqentry_a1_v [tail1] <= `INV;
6669
                                                                     iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6670
                                                                end
6671
                                                                // if no overlap, get info from rf_v and rf_source
6672
                                                                else begin
6673
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6674
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6675
                                                                end
6676
 
6677
                                                                // SOURCE 2 ...
6678
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6679
                                                                if (~fetchbuf0_rfw) begin
6680
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6681
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6682
                                                                end
6683
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6684
                                                                else if (Rb1s == Rt0s) begin
6685
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6686
                                                                     iqentry_a2_v [tail1] <= `INV;
6687
                                                                     iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6688
                                                                end
6689
                                                                // if no overlap, get info from rf_v and rf_source
6690
                                                                else begin
6691
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6692
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6693
                                                                end
6694
 
6695
                                                                // SOURCE 3 ...
6696
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6697
                                                                if (~fetchbuf0_rfw) begin
6698
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6699
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6700
                                                                end
6701
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6702
                                                                else if (Rc1 == Rt0) begin
6703
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6704
                                                                     iqentry_a3_v [tail1] <= `INV;
6705
                                                                     iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6706
                                                                end
6707
                                                                // if no overlap, get info from rf_v and rf_source
6708
                                                                else begin
6709
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6710
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6711
                                                                end
6712
 
6713
                                                                // if the two instructions enqueued target the same register, 
6714
                                                                // make sure only the second writes to rf_v and rf_source.
6715
                                                                // first is allowed to update rf_v and rf_source only if the
6716
                                                                // second has no target
6717
                                                                //
6718
                                                            if (fetchbuf0_rfw) begin
6719
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6720
                                                                     rf_v [ Rt0s] <= `INV;
6721
                                                            end
6722
                                                            if (fetchbuf1_rfw) begin
6723
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6724
                                                                     rf_v [ Rt1s ] <= `INV;
6725
                                                            end
6726
                                            end
6727
                                            else begin
6728
//                                                      enque1(tail1, seq_num + 5'd1, 6'd0);
6729
                                                        enque1(tail1,
6730
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6731
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6732
                                                                fetchbuf1_thrd ? seq_num1: seq_num, 6'd0);
6733
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6734
                                                                if (fetchbuf1_thrd)
6735
                                                                        seq_num1 <= seq_num1 + 5'd2;
6736
                                                                else
6737
                                                                        seq_num <= seq_num + 5'd2;
6738
                                                        end
6739
                                                        else begin
6740
                                                                        seq_num1 <= seq_num1 + 5'd1;
6741
                                                                        seq_num <= seq_num + 5'd1;
6742
                                                        end
6743
 
6744
                                                                // SOURCE 1 ...
6745
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6746
                                                                if (~fetchbuf0_rfw) begin
6747
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6748
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6749
                                                                end
6750
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6751
                                                                else if (Ra1s == Rt0s) begin
6752
                                                                     iqentry_a1_v [tail1] <= `INV;
6753
                                                                     iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
6754
                                                                end
6755
                                                                // if no overlap, get info from regIsValid and rf_source
6756
                                                                else begin
6757
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6758
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6759
                                                                end
6760
 
6761
                                                                // SOURCE 2 ...
6762
                                                                // if the argument is an immediate or not needed, we're done
6763
                                                                $display("Rb1s=%h, Rt0s=%h", Rb1s, Rt0s);
6764
                                                                $display("instr=%h", fetchbuf1_instr);
6765
                                                                // if previous instruction writes nothing to RF, then get info from regIsValid and rf_source
6766
                                                                if (~fetchbuf0_rfw) begin
6767
                                                                        $display("fetchbuf0_rfw=0");
6768
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6769
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6770
                                                                end
6771
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6772
                                                                else if (Rb1s == Rt0s) begin
6773
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6774
                                                                     iqentry_a2_v [tail1] <= `INV;
6775
                                                                     iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
6776
                                                                end
6777
                                                                // if no overlap, get info from regIsValid and rf_source
6778
                                                                else begin
6779
                                                                                $display("No overlap");
6780
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6781
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6782
                                                                end
6783
 
6784
                                                                // SOURCE 3 ...
6785
                                                                // if previous instruction writes nothing to RF, then get info from regIsValid and rf_source
6786
                                                                if (~fetchbuf0_rfw) begin
6787
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6788
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6789
                                                                end
6790
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6791
                                                                else if (Rc1s == Rt0s) begin
6792
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6793
                                                                     iqentry_a3_v [tail1] <= `INV;
6794
                                                                     iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
6795
                                                                end
6796
                                                                // if no overlap, get info from regIsValid and rf_source
6797
                                                                else begin
6798
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6799
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6800
                                                                end
6801
 
6802
                                                                // if the two instructions enqueued target the same register, 
6803
                                                                // make sure only the second writes to regIsValid and rf_source.
6804
                                                                // first is allowed to update regIsValid and rf_source only if the
6805
                                                                // second has no target (BEQ or SW)
6806
                                                                //
6807
                                                            if (fetchbuf0_rfw) begin
6808
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6809
                                                                     rf_v [ Rt0s] <= `INV;
6810
                                                                     $display("r%dx (%d) Invalidated", Rt0s, Rt0s[4:0]);
6811
                                                            end
6812
                                                            else
6813
                                                                $display("No rfw");
6814
                                                            if (fetchbuf1_rfw) begin
6815
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6816
                                                                     $display("r%dx (%d) Invalidated", Rt1s, Rt1s[4:0]);
6817
                                                                     rf_v [ Rt1s ] <= `INV;
6818
                                                            end
6819
                                                            else
6820
                                                                $display("No rfw");
6821
                                                        end
6822
 
6823
                                            end // ends the "if IQ[tail1] is available" clause
6824
                                            else begin  // only first instruction was enqueued
6825
                                                        if (fetchbuf0_rfw) begin
6826
                                                             $display("r%dx (%d) Invalidated 1", Rt0s, Rt0s[4:0]);
6827
                                                             rf_source[ Rt0s ] <= {1'b0,fetchbuf0_memld, tail0};
6828
                                                             rf_v [ Rt0s ] <= `INV;
6829
                                                        end
6830
                                                end
6831
                                    end
6832
 
6833
                                end     // ends the "else fetchbuf0 doesn't have a backwards branch" clause
6834
                    end
6835
                endcase
6836
        if (pebm) begin
6837
                if (branchmiss_thrd==1'b0)
6838
                        seq_num <= seq_num + 5'd3;
6839
                else
6840
                        seq_num1 <= seq_num1 + 5'd3;
6841
        end
6842
 
6843
//
6844
// DATAINCOMING
6845
//
6846
// wait for operand/s to appear on alu busses and puts them into 
6847
// the iqentry_a1 and iqentry_a2 slots (if appropriate)
6848
// as well as the appropriate iqentry_res slots (and setting valid bits)
6849
//
6850
// put results into the appropriate instruction entries
6851
//
6852
// This chunk of code has to be before the enqueue stage so that the agen bit
6853
// can be reset to zero by enqueue.
6854
// put results into the appropriate instruction entries
6855
//
6856
if (IsMul(alu0_instr)|IsDivmod(alu0_instr)|alu0_shft48) begin
6857
        if (alu0_done) begin
6858
                alu0_dataready <= `TRUE;
6859
        end
6860
end
6861
 
6862
if (alu0_v) begin
6863
        iqentry_tgt [ alu0_id[`QBITS] ] <= alu0_tgt;
6864
        iqentry_res     [ alu0_id[`QBITS] ] <= alu0_bus;
6865
        iqentry_exc     [ alu0_id[`QBITS] ] <= alu0_exc;
6866
        iqentry_done[ alu0_id[`QBITS] ] <= !iqentry_mem[ alu0_id[`QBITS] ] && alu0_done;
6867
        iqentry_cmt[ alu0_id[`QBITS] ] <= !iqentry_mem[ alu0_id[`QBITS] ] && alu0_done;
6868
        iqentry_out     [ alu0_id[`QBITS] ] <= `INV;
6869
        iqentry_agen[ alu0_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
6870
        alu0_dataready <= FALSE;
6871
end
6872
 
6873 49 robfinch
if (alu1_v && `NUM_ALU > 1) begin
6874 48 robfinch
        iqentry_tgt [ alu1_id[`QBITS] ] <= alu1_tgt;
6875
        iqentry_res     [ alu1_id[`QBITS] ] <= alu1_bus;
6876
        iqentry_exc     [ alu1_id[`QBITS] ] <= alu1_exc;
6877
        iqentry_done[ alu1_id[`QBITS] ] <= !iqentry_mem[ alu1_id[`QBITS] ] && alu1_done;
6878
        iqentry_cmt[ alu1_id[`QBITS] ] <= !iqentry_mem[ alu1_id[`QBITS] ] && alu1_done;
6879
        iqentry_out     [ alu1_id[`QBITS] ] <= `INV;
6880
        iqentry_agen[ alu1_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
6881
        alu1_dataready <= FALSE;
6882
end
6883
 
6884 49 robfinch
if (fpu1_v) begin
6885
        iqentry_res    [ fpu1_id[`QBITS] ] <= fpu1_bus;
6886
        iqentry_a0     [ fpu1_id[`QBITS] ] <= fpu1_status;
6887
        iqentry_exc    [ fpu1_id[`QBITS] ] <= fpu1_exc;
6888
        iqentry_done[ fpu1_id[`QBITS] ] <= fpu1_done;
6889
        iqentry_cmt[ fpu1_id[`QBITS] ] <= fpu1_done;
6890
        iqentry_out    [ fpu1_id[`QBITS] ] <= `INV;
6891 48 robfinch
        //iqentry_agen[ fpu_id[`QBITS] ] <= `VAL;  // RET
6892 49 robfinch
        fpu1_dataready <= FALSE;
6893 48 robfinch
end
6894
 
6895 49 robfinch
if (fpu2_v && `NUM_FPU > 1) begin
6896
        iqentry_res    [ fpu2_id[`QBITS] ] <= fpu2_bus;
6897
        iqentry_a0     [ fpu2_id[`QBITS] ] <= fpu2_status;
6898
        iqentry_exc    [ fpu2_id[`QBITS] ] <= fpu2_exc;
6899
        iqentry_done[ fpu2_id[`QBITS] ] <= fpu2_done;
6900
        iqentry_cmt[ fpu2_id[`QBITS] ] <= fpu2_done;
6901
        iqentry_out    [ fpu2_id[`QBITS] ] <= `INV;
6902
        //iqentry_agen[ fpu_id[`QBITS] ] <= `VAL;  // RET
6903
        fpu2_dataready <= FALSE;
6904
end
6905
 
6906
        if (fcu_wr & ~fcu_done) begin
6907 48 robfinch
            if (fcu_ld)
6908
                waitctr <= fcu_argA;
6909
        iqentry_res [ fcu_id[`QBITS] ] <= fcu_bus;
6910
        iqentry_exc [ fcu_id[`QBITS] ] <= fcu_exc;
6911
        if (IsWait(fcu_instr)) begin
6912
             iqentry_done [ fcu_id[`QBITS] ] <= (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]];
6913
             iqentry_cmt [ fcu_id[`QBITS] ] <= (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]];
6914
             fcu_done <= `TRUE;
6915
        end
6916
        else begin
6917
             iqentry_done[ fcu_id[`QBITS] ] <= `TRUE;
6918
             iqentry_cmt[ fcu_id[`QBITS] ] <= `TRUE;
6919
             fcu_done <= `TRUE;
6920
        end
6921
//            if (IsWait(fcu_instr) ? (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]] : !IsMem(fcu_instr) && !IsImmp(fcu_instr))
6922
//                iqentry_instr[ dram_id[`QBITS]] <= `NOP_INSN;
6923
        // Only safe place to propagate the miss pc is a0.
6924
        iqentry_a0[ fcu_id[`QBITS] ] <= fcu_misspc;
6925
        // Update branch taken indicator.
6926
        if (IsJAL(fcu_instr) || IsRet(fcu_instr) || IsBrk(fcu_instr) || IsRTI(fcu_instr) ) begin
6927
             iqentry_bt[ fcu_id[`QBITS] ] <= `VAL;
6928
            // Only safe place to propagate the miss pc is a0.
6929
//             iqentry_a0[ fcu_id[`QBITS] ] <= fcu_misspc;
6930
        end
6931
        else if (IsBranch(fcu_instr)) begin
6932
             iqentry_bt[ fcu_id[`QBITS] ] <= fcu_takb;
6933
//             iqentry_a0[ fcu_id[`QBITS] ] <= fcu_misspc;
6934
        end
6935
         iqentry_out [ fcu_id[`QBITS] ] <= `INV;
6936
         //iqentry_agen[ fcu_id[`QBITS] ] <= `VAL;//!IsRet(fcu_instr);
6937
        fcu_dataready <= `VAL;
6938
         //fcu_dataready <= fcu_branchmiss || !iqentry_agen[ fcu_id[`QBITS] ] || !(iqentry_mem[ fcu_id[`QBITS] ] && IsLoad(iqentry_instr[fcu_id[`QBITS]]));
6939
         //fcu_instr[`INSTRUCTION_OP] <= fcu_branchmiss|| (!IsMem(fcu_instr) && !IsWait(fcu_instr))? `NOP : fcu_instr[`INSTRUCTION_OP]; // to clear branchmiss
6940
        end
6941
        // Clear a branch miss when target instruction is fetched.
6942
        if (fcu_branchmiss) begin
6943
                if ((fetchbuf0_v && fetchbuf0_pc==misspc) ||
6944
                        (fetchbuf1_v && fetchbuf1_pc==misspc))
6945
                fcu_clearbm <= `TRUE;
6946
                //fcu_instr[`INSTRUCTION_OP] <= `NOP;
6947
                //iqentry_instr[fcu_id][`INSTRUCTION_OP] <= `NOP;
6948
        end
6949
//      if (dram_v && iqentry_v[ dram_id[`QBITS] ] && iqentry_mem[ dram_id[`QBITS] ] ) begin    // if data for stomped instruction, ignore
6950 49 robfinch
        if (mem1_available && dramA_v && iqentry_v[ dramA_id[`QBITS] ] && iqentry_load[ dramA_id[`QBITS] ]) begin       // if data for stomped instruction, ignore
6951 48 robfinch
                iqentry_res     [ dramA_id[`QBITS] ] <= dramA_bus;
6952
        iqentry_exc     [ dramA_id[`QBITS] ] <= dramA_exc;
6953
        iqentry_done[ dramA_id[`QBITS] ] <= `VAL;
6954
        iqentry_out [ dramA_id[`QBITS] ] <= `INV;
6955
        iqentry_cmt[ dramA_id[`QBITS] ] <= `VAL;
6956
            iqentry_aq  [ dramA_id[`QBITS] ] <= `INV;
6957
//          if (iqentry_lptr[dram0_id[`QBITS]])
6958
//              wbrcd[pcr[5:0]] <= 1'b1;
6959
        end
6960 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
6961 48 robfinch
        iqentry_res     [ dramB_id[`QBITS] ] <= dramB_bus;
6962
        iqentry_exc     [ dramB_id[`QBITS] ] <= dramB_exc;
6963
        iqentry_done[ dramB_id[`QBITS] ] <= `VAL;
6964
        iqentry_out [ dramB_id[`QBITS] ] <= `INV;
6965
        iqentry_cmt[ dramB_id[`QBITS] ] <= `VAL;
6966
            iqentry_aq  [ dramB_id[`QBITS] ] <= `INV;
6967
//          if (iqentry_lptr[dram1_id[`QBITS]])
6968
//              wbrcd[pcr[5:0]] <= 1'b1;
6969
        end
6970 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
6971 48 robfinch
        iqentry_res     [ dramC_id[`QBITS] ] <= dramC_bus;
6972
        iqentry_exc     [ dramC_id[`QBITS] ] <= dramC_exc;
6973
        iqentry_done[ dramC_id[`QBITS] ] <= `VAL;
6974
        iqentry_out [ dramC_id[`QBITS] ] <= `INV;
6975
        iqentry_cmt[ dramC_id[`QBITS] ] <= `VAL;
6976
            iqentry_aq  [ dramC_id[`QBITS] ] <= `INV;
6977
//          if (iqentry_lptr[dram2_id[`QBITS]])
6978
//              wbrcd[pcr[5:0]] <= 1'b1;
6979
        end
6980
 
6981
//
6982
// set the IQ entry == DONE as soon as the SW is let loose to the memory system
6983
//
6984 50 robfinch
if (mem1_available && dram0 == `DRAMSLOT_BUSY && dram0_store) begin
6985 48 robfinch
        if ((alu0_v && (dram0_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram0_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6986
        iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
6987
        iqentry_out[ dram0_id[`QBITS] ] <= `INV;
6988
end
6989 50 robfinch
if (mem2_available && `NUM_MEM > 1 && dram1 == `DRAMSLOT_BUSY && dram1_store) begin
6990 48 robfinch
        if ((alu0_v && (dram1_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram1_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6991
        iqentry_done[ dram1_id[`QBITS] ] <= `VAL;
6992
        iqentry_out[ dram1_id[`QBITS] ] <= `INV;
6993
end
6994 50 robfinch
if (mem3_available && `NUM_MEM > 2 && dram2 == `DRAMSLOT_BUSY && dram2_store) begin
6995 48 robfinch
        if ((alu0_v && (dram2_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram2_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6996
        iqentry_done[ dram2_id[`QBITS] ] <= `VAL;
6997
        iqentry_out[ dram2_id[`QBITS] ] <= `INV;
6998
end
6999
 
7000
//
7001
// see if anybody else wants the results ... look at lots of buses:
7002
//  - fpu_bus
7003
//  - alu0_bus
7004
//  - alu1_bus
7005
//  - fcu_bus
7006
//  - dram_bus
7007
//  - commit0_bus
7008
//  - commit1_bus
7009
//
7010
 
7011
for (n = 0; n < QENTRIES; n = n + 1)
7012
begin
7013 49 robfinch
        if (`NUM_FPU > 0)
7014
                setargs(n,{1'b0,fpu1_id},fpu1_v,fpu1_bus);
7015
        if (`NUM_FPU > 1)
7016
                setargs(n,{1'b0,fpu2_id},fpu2_v,fpu2_bus);
7017
 
7018 48 robfinch
        setargs(n,{1'b0,alu0_id},alu0_v,alu0_bus);
7019 49 robfinch
        if (`NUM_ALU > 1)
7020
                setargs(n,{1'b0,alu1_id},alu1_v,alu1_bus);
7021
 
7022 48 robfinch
        setargs(n,{1'b0,fcu_id},fcu_wr,fcu_bus);
7023 49 robfinch
 
7024 48 robfinch
        setargs(n,{1'b0,dramA_id},dramA_v,dramA_bus);
7025 49 robfinch
        if (`NUM_MEM > 1)
7026
                setargs(n,{1'b0,dramB_id},dramB_v,dramB_bus);
7027
        if (`NUM_MEM > 2)
7028
                setargs(n,{1'b0,dramC_id},dramC_v,dramC_bus);
7029
 
7030 48 robfinch
        setargs(n,commit0_id,commit0_v,commit0_bus);
7031 49 robfinch
        if (`NUM_CMT > 1)
7032
                setargs(n,commit1_id,commit1_v,commit1_bus);
7033 48 robfinch
 
7034
        setinsn(n[`QBITS],id1_ido,id1_available&id1_vo,id1_bus);
7035 49 robfinch
        if (`NUM_IDU > 1)
7036
                setinsn(n[`QBITS],id2_ido,id2_available&id2_vo,id2_bus);
7037
        if (`NUM_IDU > 2)
7038
                setinsn(n[`QBITS],id3_ido,id3_available&id3_vo,id3_bus);
7039 48 robfinch
end
7040
 
7041
//
7042
// ISSUE 
7043
//
7044
// determines what instructions are ready to go, then places them
7045
// in the various ALU queues.  
7046
// also invalidates instructions following a branch-miss BEQ or any JALR (STOMP logic)
7047
//
7048
 
7049
for (n = 0; n < QENTRIES; n = n + 1)
7050
if (id1_available) begin
7051
if (iqentry_id1issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7052
                id1_vi <= `VAL;
7053
                id1_id                  <= n[4:0];
7054
                id1_instr       <= iqentry_rtop[n] ? (
7055
                                                                                iqentry_a3_v[n] ? iqentry_a3[n]
7056 49 robfinch
`ifdef FU_BYPASS
7057 48 robfinch
                                : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7058
                                : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7059 49 robfinch
`endif
7060 48 robfinch
                                : `NOP_INSN)
7061
                                                                 : iqentry_instr[n];
7062
                id1_ven    <= iqentry_ven[n];
7063
                id1_vl     <= iqentry_vl[n];
7064
                id1_thrd   <= iqentry_thrd[n];
7065
                id1_Rt     <= iqentry_tgt[n][4:0];
7066
                id1_pt                  <= iqentry_pt[n];
7067
  end
7068
end
7069 49 robfinch
if (`NUM_IDU > 1) begin
7070 48 robfinch
for (n = 0; n < QENTRIES; n = n + 1)
7071 49 robfinch
        if (id2_available) begin
7072
                if (iqentry_id2issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7073
                        id2_vi <= `VAL;
7074
                        id2_id                  <= n[4:0];
7075
                        id2_instr       <= iqentry_rtop[n] ? (
7076
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7077
`ifdef FU_BYPASS
7078
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7079
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7080
`endif
7081
                                        : `NOP_INSN)
7082
                                                                         : iqentry_instr[n];
7083
                        id2_ven    <= iqentry_ven[n];
7084
                        id2_vl     <= iqentry_vl[n];
7085
                        id2_thrd   <= iqentry_thrd[n];
7086
                        id2_Rt     <= iqentry_tgt[n][4:0];
7087
                        id2_pt                  <= iqentry_pt[n];
7088
                end
7089 48 robfinch
        end
7090
end
7091 49 robfinch
if (`NUM_IDU > 2) begin
7092
for (n = 0; n < QENTRIES; n = n + 1)
7093
        if (id3_available) begin
7094
                if (iqentry_id3issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7095
                        id3_vi <= `VAL;
7096
                        id3_id                  <= n[4:0];
7097
                        id3_instr       <= iqentry_rtop[n] ? (
7098
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7099
`ifdef FU_BYPASS
7100
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7101
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7102
`endif
7103
                                        : `NOP_INSN)
7104
                                                                         : iqentry_instr[n];
7105
                        id3_ven    <= iqentry_ven[n];
7106
                        id3_vl     <= iqentry_vl[n];
7107
                        id3_thrd   <= iqentry_thrd[n];
7108
                        id3_Rt     <= iqentry_tgt[n][4:0];
7109
                        id3_pt                  <= iqentry_pt[n];
7110
                end
7111
        end
7112
end
7113 48 robfinch
 
7114
    for (n = 0; n < QENTRIES; n = n + 1)
7115
        if (iqentry_alu0_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7116
            if (alu0_available & alu0_done) begin
7117
                 alu0_sourceid  <= n[3:0];
7118
                 alu0_instr     <= iqentry_rtop[n] ? (
7119 49 robfinch
`ifdef FU_BYPASS
7120 48 robfinch
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7121 49 robfinch
                                                    : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7122
                                                    : (iqentry_a3_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7123
                                                    : alu1_bus)
7124
`else
7125
                                                                                                                                        iqentry_a3[n])
7126
`endif
7127 48 robfinch
                                                                         : iqentry_instr[n];
7128
                 alu0_bt                <= iqentry_bt[n];
7129
                 alu0_mem   <= iqentry_mem[n];
7130
                 alu0_shft48 <= iqentry_shft48[n];
7131
                 alu0_pc                <= iqentry_pc[n];
7132 49 robfinch
                 alu0_argA      <=
7133
`ifdef FU_BYPASS
7134
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7135
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7136
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7137
                            : alu1_bus;
7138
`else
7139
                                                                                                                iqentry_a1[n];
7140
`endif
7141 48 robfinch
                 alu0_argB      <= iqentry_imm[n]
7142
                            ? iqentry_a0[n]
7143 49 robfinch
`ifdef FU_BYPASS
7144 48 robfinch
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
7145 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7146
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7147
                            : alu1_bus);
7148
`else
7149
                                                                                                                : iqentry_a2[n];
7150
`endif
7151
                 alu0_argC      <=
7152
`ifdef FU_BYPASS
7153
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7154 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7155 49 robfinch
`else
7156
                                                                                                                        iqentry_a3[n];
7157
`endif
7158 48 robfinch
                 alu0_argI      <= iqentry_a0[n];
7159
                 alu0_tgt    <= IsVeins(iqentry_instr[n]) ?
7160 49 robfinch
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((
7161
                                                                                        iqentry_a2_v[n] ? iqentry_a2[n][5:0]
7162 48 robfinch
                                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus[5:0]
7163
                                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus[5:0]
7164
                                            : {4{16'h0000}})) << 6 :
7165
                                iqentry_tgt[n];
7166
                 alu0_ven    <= iqentry_ven[n];
7167
                 alu0_thrd   <= iqentry_thrd[n];
7168
                 alu0_dataready <= IsSingleCycle(iqentry_instr[n]);
7169
                 alu0_ld <= TRUE;
7170
                 iqentry_out[n] <= `VAL;
7171
                // if it is a memory operation, this is the address-generation step ... collect result into arg1
7172
                if (iqentry_mem[n]) begin
7173
                 iqentry_a1_v[n] <= `INV;
7174
                 iqentry_a1_s[n] <= n[3:0];
7175
                end
7176
            end
7177
        end
7178 49 robfinch
        if (`NUM_ALU > 1) begin
7179 48 robfinch
    for (n = 0; n < QENTRIES; n = n + 1)
7180
        if (iqentry_alu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7181
            if (alu1_available && alu1_done) begin
7182
                        if (iqentry_alu0[n])
7183
                                panic <= `PANIC_ALU0ONLY;
7184
                 alu1_sourceid  <= n[3:0];
7185
                 alu1_instr     <= iqentry_instr[n];
7186
                 alu1_bt                <= iqentry_bt[n];
7187
                 alu1_mem   <= iqentry_mem[n];
7188
                 alu1_shft48 <= iqentry_shft48[n];
7189
                 alu1_pc                <= iqentry_pc[n];
7190 49 robfinch
                 alu1_argA      <=
7191
`ifdef FU_BYPASS
7192
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7193
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7194
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7195
                            : alu1_bus;
7196
`else
7197
                                                                                                                        iqentry_a1[n];
7198
`endif
7199 48 robfinch
                 alu1_argB      <= iqentry_imm[n]
7200
                            ? iqentry_a0[n]
7201 49 robfinch
`ifdef FU_BYPASS
7202 48 robfinch
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
7203 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7204
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7205
                            : alu1_bus);
7206
`else
7207
                                                                                                                : iqentry_a2[n];
7208
`endif
7209
                 alu1_argC      <=
7210
`ifdef FU_BYPASS
7211
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7212 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7213 49 robfinch
`else
7214
                                                                                                                        iqentry_a3[n];
7215
`endif
7216 48 robfinch
                 alu1_argI      <= iqentry_a0[n];
7217
                 alu1_tgt    <= IsVeins(iqentry_instr[n]) ?
7218
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((iqentry_a2_v[n] ? iqentry_a2[n][5:0]
7219
                                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus[5:0]
7220
                                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus[5:0]
7221
                                            : {4{16'h0000}})) << 6 :
7222
                                iqentry_tgt[n];
7223
                 alu1_ven    <= iqentry_ven[n];
7224
                 alu1_dataready <= IsSingleCycle(iqentry_instr[n]);
7225
                 alu1_ld <= TRUE;
7226
                 iqentry_out[n] <= `VAL;
7227
                // if it is a memory operation, this is the address-generation step ... collect result into arg1
7228
                if (iqentry_mem[n]) begin
7229
                 iqentry_a1_v[n] <= `INV;
7230
                 iqentry_a1_s[n] <= n[3:0];
7231
                end
7232
            end
7233
        end
7234 49 robfinch
  end
7235 48 robfinch
 
7236
    for (n = 0; n < QENTRIES; n = n + 1)
7237 49 robfinch
        if (iqentry_fpu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7238
            if (fpu1_available & fpu1_done) begin
7239
                 fpu1_sourceid  <= n[3:0];
7240
                 fpu1_instr     <= iqentry_instr[n];
7241
                 fpu1_pc                <= iqentry_pc[n];
7242
                 fpu1_argA      <=
7243
`ifdef FU_BYPASS
7244
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7245
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7246
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7247
                            : alu1_bus;
7248
`else
7249
                                                                                                                        iqentry_a1[n];
7250
`endif
7251
                 fpu1_argB      <=
7252
`ifdef FU_BYPASS
7253
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
7254
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7255
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7256
                            : alu1_bus);
7257
`else
7258
                                                                                                                        iqentry_a2[n];
7259
`endif
7260
                 fpu1_argC      <=
7261
`ifdef FU_BYPASS
7262
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
7263 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7264 49 robfinch
`else
7265
                                                                                                                        iqentry_a3[n];
7266
`endif
7267
                 fpu1_argI      <= iqentry_a0[n];
7268
                 fpu1_dataready <= `VAL;
7269
                 fpu1_ld <= TRUE;
7270 48 robfinch
                 iqentry_out[n] <= `VAL;
7271
            end
7272
        end
7273
 
7274
    for (n = 0; n < QENTRIES; n = n + 1)
7275 49 robfinch
        if (`NUM_FPU > 1 && iqentry_fpu2_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7276
            if (fpu2_available & fpu2_done) begin
7277
                 fpu2_sourceid  <= n[3:0];
7278
                 fpu2_instr     <= iqentry_instr[n];
7279
                 fpu2_pc                <= iqentry_pc[n];
7280
                 fpu2_argA      <=
7281
`ifdef FU_BYPASS
7282
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7283
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7284
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7285
                            : alu1_bus;
7286
`else
7287
                                                                                                                        iqentry_a1[n];
7288
`endif
7289
                 fpu2_argB      <=
7290
`ifdef FU_BYPASS
7291
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
7292
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7293
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7294
                            : alu1_bus);
7295
`else
7296
                                                                                                                        iqentry_a2[n];
7297
`endif
7298
                 fpu2_argC      <=
7299
`ifdef FU_BYPASS
7300
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
7301
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7302
`else
7303
                                                                                                                        iqentry_a3[n];
7304
`endif
7305
                 fpu2_argI      <= iqentry_a0[n];
7306
                 fpu2_dataready <= `VAL;
7307
                 fpu2_ld <= TRUE;
7308
                 iqentry_out[n] <= `VAL;
7309
            end
7310
        end
7311
 
7312
    for (n = 0; n < QENTRIES; n = n + 1)
7313 48 robfinch
        if (iqentry_fcu_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7314
            if (fcu_done) begin
7315
                 fcu_sourceid   <= n[3:0];
7316
                 fcu_instr      <= iqentry_instr[n];
7317
                 fcu_insln  <= iqentry_insln[n];
7318
                 fcu_pc         <= iqentry_pc[n];
7319
                 fcu_nextpc <= iqentry_pc[n] + iqentry_insln[n];
7320
                 fcu_brdisp <= {{52{iqentry_instr[n][31]}},iqentry_instr[n][31:21],1'b0};
7321
                 fcu_call    <= IsCall(iqentry_instr[n])|IsJAL(iqentry_instr[n]);
7322
                 fcu_bt         <= iqentry_bt[n];
7323
                 fcu_pc         <= iqentry_pc[n];
7324
                 fcu_argA       <= iqentry_a1_v[n] ? iqentry_a1[n]
7325 49 robfinch
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7326
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7327
                            : alu1_bus;
7328 48 robfinch
`ifdef SUPPORT_SMT
7329
                 fcu_argB       <= IsRTI(iqentry_instr[n]) ? epc0[iqentry_thrd[n]]
7330
`else
7331
                 fcu_argB       <= IsRTI(iqentry_instr[n]) ? epc0
7332
`endif
7333
                                        : (iqentry_a2_v[n] ? iqentry_a2[n]
7334 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7335
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7336
                            : alu1_bus);
7337 48 robfinch
                 waitctr            <= iqentry_imm[n]
7338
                            ? iqentry_a0[n]
7339
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
7340
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus : alu1_bus);
7341
                 fcu_argC       <= iqentry_a3_v[n] ? iqentry_a3[n]
7342
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7343
                 fcu_argI       <= iqentry_a0[n];
7344
                 fcu_thrd   <= iqentry_thrd[n];
7345
                 fcu_dataready <= `VAL;
7346
                 fcu_clearbm <= `FALSE;
7347
                 fcu_retadr_v <= `INV;
7348
                 fcu_ld <= TRUE;
7349
                 fcu_timeout <= 8'h00;
7350
                 iqentry_out[n] <= `VAL;
7351
                 fcu_done <= `FALSE;
7352
            end
7353
        end
7354
//
7355
// MEMORY
7356
//
7357
// update the memory queues and put data out on bus if appropriate
7358
//
7359
 
7360
//
7361
// dram0, dram1, dram2 are the "state machines" that keep track
7362
// of three pipelined DRAM requests.  if any has the value "00", 
7363
// then it can accept a request (which bumps it up to the value "01"
7364
// at the end of the cycle).  once it hits the value "11" the request
7365
// is finished and the dram_bus takes the value.  if it is a store, the 
7366
// dram_bus value is not used, but the dram_v value along with the
7367
// dram_id value signals the waiting memq entry that the store is
7368
// completed and the instruction can commit.
7369
//
7370
 
7371
//      if (dram0 != `DRAMSLOT_AVAIL)   dram0 <= dram0 + 2'd1;
7372
//      if (dram1 != `DRAMSLOT_AVAIL)   dram1 <= dram1 + 2'd1;
7373
//      if (dram2 != `DRAMSLOT_AVAIL)   dram2 <= dram2 + 2'd1;
7374
 
7375
//
7376
// grab requests that have finished and put them on the dram_bus
7377 49 robfinch
if (mem1_available && dram0 == `DRAMREQ_READY) begin
7378 48 robfinch
        dram0 <= `DRAMSLOT_AVAIL;
7379
        dramA_v <= dram0_load;
7380
        dramA_id <= dram0_id;
7381
        dramA_exc <= dram0_exc;
7382
        dramA_bus <= fnDati(dram0_instr,dram0_addr,rdat0);
7383 50 robfinch
        if (dram0_store)        $display("m[%h] <- %h", dram0_addr, dram0_data);
7384 48 robfinch
end
7385
//    else
7386
//      dramA_v <= `INV;
7387 49 robfinch
if (mem2_available && dram1 == `DRAMREQ_READY && `NUM_MEM > 1) begin
7388 48 robfinch
        dram1 <= `DRAMSLOT_AVAIL;
7389
        dramB_v <= dram1_load;
7390
        dramB_id <= dram1_id;
7391
        dramB_exc <= dram1_exc;
7392
        dramB_bus <= fnDati(dram1_instr,dram1_addr,rdat1);
7393 50 robfinch
        if (dram1_store)     $display("m[%h] <- %h", dram1_addr, dram1_data);
7394 48 robfinch
end
7395
//    else
7396
//      dramB_v <= `INV;
7397 49 robfinch
if (mem3_available && dram2 == `DRAMREQ_READY && `NUM_MEM > 2) begin
7398 48 robfinch
        dram2 <= `DRAMSLOT_AVAIL;
7399
        dramC_v <= dram2_load;
7400
        dramC_id <= dram2_id;
7401
        dramC_exc <= dram2_exc;
7402
        dramC_bus <= fnDati(dram2_instr,dram2_addr,rdat2);
7403 50 robfinch
        if (dram2_store)     $display("m[%h] <- %h", dram2_addr, dram2_data);
7404 48 robfinch
end
7405
//    else
7406
//      dramC_v <= `INV;
7407
 
7408
        //
7409
        // determine if the instructions ready to issue can, in fact, issue.
7410
        // "ready" means that the instruction has valid operands but has not gone yet
7411
        iqentry_memissue <= memissue;
7412
        missue_count <= issue_count;
7413
 
7414
 
7415
        //
7416
        // take requests that are ready and put them into DRAM slots
7417
 
7418
        if (dram0 == `DRAMSLOT_AVAIL)    dram0_exc <= `FLT_NONE;
7419
        if (dram1 == `DRAMSLOT_AVAIL)    dram1_exc <= `FLT_NONE;
7420
        if (dram2 == `DRAMSLOT_AVAIL)    dram2_exc <= `FLT_NONE;
7421
 
7422
        for (n = 0; n < QENTRIES; n = n + 1)
7423
                if (iqentry_v[n] && iqentry_stomp[n]) begin
7424
                        iqentry_v[n] <= `INV;
7425
                        iqentry_iv[n] <= `INV;
7426
                        if (dram0_id[`QBITS] == n[`QBITS])  dram0 <= `DRAMSLOT_AVAIL;
7427
                        if (dram1_id[`QBITS] == n[`QBITS])  dram1 <= `DRAMSLOT_AVAIL;
7428
                        if (dram2_id[`QBITS] == n[`QBITS])  dram2 <= `DRAMSLOT_AVAIL;
7429
                end
7430
 
7431
        last_issue = 8;
7432
    for (n = 0; n < QENTRIES; n = n + 1)
7433 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7434
            if (mem1_available && dram0 == `DRAMSLOT_AVAIL) begin
7435 48 robfinch
                dramA_v <= `INV;
7436
             dram0              <= `DRAMSLOT_BUSY;
7437
             dram0_id   <= { 1'b1, n[`QBITS] };
7438
             dram0_instr <= iqentry_instr[n];
7439
             dram0_rmw  <= iqentry_rmw[n];
7440
             dram0_preload <= iqentry_preload[n];
7441
             dram0_tgt  <= iqentry_tgt[n];
7442
             dram0_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7443
             dram0_addr <= iqentry_a1[n];
7444
//             if (ol[iqentry_thrd[n]]==`OL_USER)
7445
//              dram0_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7446
//             else
7447 50 robfinch
             dram0_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
7448
             dram0_memsize <= iqentry_memsz[n];
7449 48 robfinch
             dram0_load <= iqentry_load[n];
7450 50 robfinch
             dram0_store <= iqentry_store[n];
7451 48 robfinch
             dram0_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
7452
             // Once the memory op is issued reset the a1_v flag.
7453
             // This will cause the a1 bus to look for new data from memory (a1_s is pointed to a memory bus)
7454
             // This is used for the load and compare instructions.
7455
             iqentry_a1_v[n] <= `INV;
7456
             last_issue = n;
7457
            end
7458
        end
7459
    if (last_issue < 8)
7460
        iqentry_out[last_issue] <= `VAL;
7461
    for (n = 0; n < QENTRIES; n = n + 1)
7462 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7463
                if (mem2_available && n < last_issue && `NUM_MEM > 1) begin
7464 48 robfinch
                    if (dram1 == `DRAMSLOT_AVAIL) begin
7465
                        dramB_v <= `INV;
7466
                     dram1              <= `DRAMSLOT_BUSY;
7467
                     dram1_id   <= { 1'b1, n[`QBITS] };
7468
                     dram1_instr <= iqentry_instr[n];
7469
                     dram1_rmw  <= iqentry_rmw[n];
7470
                     dram1_preload <= iqentry_preload[n];
7471
                     dram1_tgt  <= iqentry_tgt[n];
7472
                     dram1_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7473
                     dram1_addr <= iqentry_a1[n];
7474
//                   if (ol[iqentry_thrd[n]]==`OL_USER)
7475
//                      dram1_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7476
//                   else
7477 50 robfinch
                     dram1_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
7478
                     dram1_memsize <= iqentry_memsz[n];
7479 48 robfinch
                     dram1_load <= iqentry_load[n];
7480 50 robfinch
                     dram1_store <= iqentry_store[n];
7481 48 robfinch
                     dram1_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
7482
                     iqentry_a1_v[n] <= `INV;
7483
                     last_issue = n;
7484
                    end
7485
                end
7486
        end
7487
    if (last_issue < 8)
7488
        iqentry_out[last_issue] <= `VAL;
7489
    for (n = 0; n < QENTRIES; n = n + 1)
7490 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7491
                if (mem3_available && n < last_issue && `NUM_MEM > 2) begin
7492 48 robfinch
                    if (dram2 == `DRAMSLOT_AVAIL) begin
7493
                        dramC_v <= `INV;
7494
                     dram2              <= `DRAMSLOT_BUSY;
7495
                     dram2_id   <= { 1'b1, n[`QBITS] };
7496
                     dram2_instr        <= iqentry_instr[n];
7497
                     dram2_rmw  <= iqentry_rmw[n];
7498
                     dram2_preload <= iqentry_preload[n];
7499
                     dram2_tgt  <= iqentry_tgt[n];
7500
                     dram2_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7501
                     dram2_addr <= iqentry_a1[n];
7502
//                   if (ol[iqentry_thrd[n]]==`OL_USER)
7503
//                      dram2_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7504
//                   else
7505 50 robfinch
                     dram2_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
7506
                     dram2_memsize <= iqentry_memsz[n];
7507 48 robfinch
                     dram2_load <= iqentry_load[n];
7508 50 robfinch
                     dram2_store <= iqentry_store[n];
7509 48 robfinch
                     dram2_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
7510
                     iqentry_a1_v[n] <= `INV;
7511
                    end
7512
                end
7513
        end
7514
    if (last_issue < 8)
7515
        iqentry_out[last_issue] <= `VAL;
7516
 
7517
    // It's better to check a sequence number here because if the code is in a
7518
    // loop that such that the previous iteration of the loop is still in the
7519
    // queue the PC could match when we don;t really want a prefix for that
7520
    // iteration.
7521
    for (n = 0; n < QENTRIES; n = n + 1)
7522
    begin
7523
        if (!iqentry_v[n])
7524
             iqentry_done[n] <= FALSE;
7525
    end
7526
 
7527
 
7528
 
7529 49 robfinch
//
7530
// COMMIT PHASE (dequeue only ... not register-file update)
7531
//
7532
// look at head0 and head1 and let 'em write to the register file if they are ready
7533
//
7534 48 robfinch
//    always @(posedge clk) begin: commit_phase
7535
 
7536 49 robfinch
oddball_commit(commit0_v, head0);
7537
if (`NUM_CMT > 1)
7538
        oddball_commit(commit1_v, head1);
7539 50 robfinch
//if (`NUM_CMT > 2)
7540
//      oddball_commit(commit2_v, head2);
7541 48 robfinch
 
7542
// Fetch and queue are limited to two instructions per cycle, so we might as
7543
// well limit retiring to two instructions max to conserve logic.
7544
//
7545
if (~|panic)
7546 49 robfinch
  casez ({ iqentry_v[head0],
7547
                iqentry_cmt[head0],
7548
                iqentry_v[head1],
7549
                iqentry_cmt[head1],
7550
                iqentry_v[head2],
7551
                iqentry_cmt[head2]})
7552 48 robfinch
 
7553
        // retire 3
7554 49 robfinch
        6'b0?_0?_0?:
7555
                if (head0 != tail0 && head1 != tail0 && head2 != tail0) begin
7556
                                head_inc(3);
7557
                end
7558
                else if (head0 != tail0 && head1 != tail0) begin
7559 48 robfinch
                    head_inc(2);
7560
                end
7561
                else if (head0 != tail0) begin
7562
                    head_inc(1);
7563
                end
7564 49 robfinch
        6'b0?_0?_10:    ;
7565
        6'b0?_0?_11:
7566
                if (`NUM_CMT > 2 || iqentry_tgt[head2][4:0]==5'd0) begin
7567
      iqentry_v[head2] <= `INV;
7568
      head_inc(3);
7569
                end
7570
                else begin
7571
      head_inc(2);
7572
                end
7573 48 robfinch
 
7574
        // retire 1 (wait for regfile for head1)
7575 49 robfinch
        6'b0?_10_??:
7576
                head_inc(1);
7577 48 robfinch
 
7578
        // retire 2
7579 49 robfinch
        6'b0?_11_0?,
7580
        6'b0?_11_10:
7581
        if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7582
          iqentry_v[head1] <= `INV;
7583
          head_inc(2);
7584 48 robfinch
        end
7585 49 robfinch
        else begin
7586
                head_inc(1);
7587
        end
7588
  6'b0?_11_11:
7589 50 robfinch
        if (`NUM_CMT > 2 || (`NUM_CMT > 1 && iqentry_tgt[head2] == 12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
7590 49 robfinch
                iqentry_v[head1] <= `INV;
7591
          iqentry_v[head2] <= `INV;
7592
                head_inc(3);
7593
        end
7594
        else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7595
                iqentry_v[head1] <= `INV;
7596
                head_inc(2);
7597
        end
7598
        else
7599
                head_inc(1);
7600
  6'b10_??_??:  ;
7601
  6'b11_0?_0?:
7602
        if (head1 != tail0 && head2 != tail0) begin
7603 48 robfinch
                        iqentry_v[head0] <= `INV;
7604 49 robfinch
                        head_inc(3);
7605
        end
7606
        else if (head1 != tail0) begin
7607
                        iqentry_v[head0] <= `INV;
7608 48 robfinch
                        head_inc(2);
7609 49 robfinch
        end
7610
        else begin
7611 48 robfinch
                        iqentry_v[head0] <= `INV;
7612
                        head_inc(1);
7613 49 robfinch
        end
7614
  6'b11_0?_10:
7615
        if (head1 != tail0) begin
7616
                        iqentry_v[head0] <= `INV;
7617
                        head_inc(2);
7618
        end
7619
        else begin
7620
                        iqentry_v[head0] <= `INV;
7621
                        head_inc(1);
7622
        end
7623
  6'b11_0?_11:
7624
        if (head1 != tail0) begin
7625 50 robfinch
                if (`NUM_CMT > 2 || (iqentry_tgt[head2]==12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
7626 49 robfinch
                                iqentry_v[head0] <= `INV;
7627
                                iqentry_v[head2] <= `INV;
7628
                                head_inc(3);
7629
                end
7630
                else begin
7631
                                iqentry_v[head0] <= `INV;
7632
                                head_inc(2);
7633
                        end
7634
        end
7635
        else begin
7636
                        iqentry_v[head0] <= `INV;
7637
                        head_inc(1);
7638
        end
7639
  6'b11_10_??:
7640
        begin
7641
                        iqentry_v[head0] <= `INV;
7642
                        head_inc(1);
7643
        end
7644
  6'b11_11_0?:
7645
        if (`NUM_CMT > 1 && head2 != tail0) begin
7646
                        iqentry_v[head0] <= `INV;
7647
                        iqentry_v[head1] <= `INV;
7648
                        head_inc(3);
7649
        end
7650
        else if (iqentry_tgt[head1]== 12'd0 && head2 != tail0) begin
7651
                        iqentry_v[head0] <= `INV;
7652
                        iqentry_v[head1] <= `INV;
7653
                        head_inc(3);
7654
        end
7655
        else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7656
                        iqentry_v[head0] <= `INV;
7657
                        iqentry_v[head1] <= `INV;
7658
                        head_inc(2);
7659
        end
7660
        else begin
7661
                        iqentry_v[head0] <= `INV;
7662
                        head_inc(1);
7663
        end
7664
  6'b11_11_10:
7665
        if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7666
                        iqentry_v[head0] <= `INV;
7667
                        iqentry_v[head1] <= `INV;
7668
                        head_inc(2);
7669
        end
7670
        else begin
7671
                        iqentry_v[head0] <= `INV;
7672
                        head_inc(1);
7673
        end
7674
        6'b11_11_11:
7675 50 robfinch
                if (`NUM_CMT > 2 || (`NUM_CMT > 1 && iqentry_tgt[head2]==12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
7676 49 robfinch
                        iqentry_v[head0] <= `INV;
7677
                        iqentry_v[head1] <= `INV;
7678
                        iqentry_v[head2] <= `INV;
7679
                        head_inc(3);
7680 48 robfinch
                end
7681 49 robfinch
                else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7682 48 robfinch
                        iqentry_v[head0] <= `INV;
7683 49 robfinch
                        iqentry_v[head1] <= `INV;
7684
                        head_inc(2);
7685
                end
7686
                else begin
7687
                        iqentry_v[head0] <= `INV;
7688 48 robfinch
                        head_inc(1);
7689
                end
7690 49 robfinch
  endcase
7691 48 robfinch
 
7692
 
7693
        rf_source[0] <= 0;
7694
        L1_wr0 <= FALSE;
7695
        L1_wr1 <= FALSE;
7696
        L1_invline <= FALSE;
7697
        icnxt <= FALSE;
7698
        L2_nxt <= FALSE;
7699
// Instruction cache state machine.
7700
// On a miss first see if the instruction is in the L2 cache. No need to go to
7701
// the BIU on an L1 miss.
7702
// If not the machine will wait until the BIU loads the L2 cache.
7703
 
7704
// Capture the previous ic state, used to determine how long to wait in
7705
// icstate #4.
7706
        picstate <= icstate;
7707
case(icstate)
7708
IDLE:
7709
        // If the bus unit is busy doing an update involving L1_adr or L2_adr
7710
        // we have to wait.
7711
        if (bstate != B7 && bstate != B9) begin
7712
                if (!ihit0) begin
7713
                        L1_adr <= {pcr[5:0],pc0[31:3],3'h0};
7714
                        L2_adr <= {pcr[5:0],pc0[31:3],3'h0};
7715
                        L1_invline <= TRUE;
7716 49 robfinch
                        icwhich <= 2'b00;
7717 48 robfinch
                        iccnt <= 3'b00;
7718
                        icstate <= IC2;
7719
                end
7720 49 robfinch
                else if (!ihit1 && `WAYS > 1) begin
7721 48 robfinch
`ifdef SUPPORT_SMT
7722
                        L1_adr <= {pcr[5:0],pc1[31:3],3'h0};
7723
                        L2_adr <= {pcr[5:0],pc1[31:3],3'h0};
7724
`else
7725
                        L1_adr <= {pcr[5:0],pc0plus6[31:3],3'h0};
7726
                        L2_adr <= {pcr[5:0],pc0plus6[31:3],3'h0};
7727
`endif
7728
                        L1_invline <= TRUE;
7729 49 robfinch
                        icwhich <= 2'b01;
7730 48 robfinch
                        iccnt <= 3'b00;
7731
                        icstate <= IC2;
7732
                end
7733 49 robfinch
                else if (!ihit2 && `WAYS > 2) begin
7734
`ifdef SUPPORT_SMT
7735
                        L1_adr <= {pcr[5:0],pc2[31:3],3'h0};
7736
                        L2_adr <= {pcr[5:0],pc2[31:3],3'h0};
7737
`else
7738
                        L1_adr <= {pcr[5:0],pc0plus12[31:3],3'h0};
7739
                        L2_adr <= {pcr[5:0],pc0plus12[31:3],3'h0};
7740
`endif
7741
                        L1_invline <= TRUE;
7742
                        icwhich <= 2'b10;
7743
                        iccnt <= 3'b00;
7744
                        icstate <= IC2;
7745
                end
7746 48 robfinch
        end
7747
IC2:     icstate <= IC3;
7748
IC3:     icstate <= IC3a;
7749
IC3a:     icstate <= IC4;
7750
        // If data was in the L2 cache already there's no need to wait on the
7751
        // BIU to retrieve data. It can be determined if the hit signal was
7752
        // already active when this state was entered in which case waiting
7753
        // will do no good.
7754
        // The IC machine will stall in this state until the BIU has loaded the
7755
        // L2 cache. 
7756
IC4:
7757 49 robfinch
        if (ihitL2 && picstate==IC3a) begin
7758
                L1_en <= 9'h1FF;
7759 48 robfinch
                L1_wr0 <= TRUE;
7760 49 robfinch
                L1_wr1 <= TRUE && `WAYS > 1;
7761
                L1_wr2 <= TRUE && `WAYS > 2;
7762 48 robfinch
                L1_adr <= L2_adr;
7763
                L2_rdat <= L2_dato;
7764
                icstate <= IC5;
7765
        end
7766
        else if (bstate!=B9)
7767
                ;
7768
        else begin
7769 49 robfinch
                L1_en <= 9'h1FF;
7770 48 robfinch
                L1_wr0 <= TRUE;
7771 49 robfinch
                L1_wr1 <= TRUE && `WAYS > 1;
7772
                L1_wr2 <= TRUE && `WAYS > 2;
7773 48 robfinch
                L1_adr <= L2_adr;
7774
                L2_rdat <= L2_dato;
7775
                icstate <= IC5;
7776
        end
7777
IC5:
7778
        begin
7779 49 robfinch
                L1_en <= 9'h000;
7780 48 robfinch
                L1_wr0 <= FALSE;
7781
                L1_wr1 <= FALSE;
7782 49 robfinch
                L1_wr2 <= FALSE;
7783 48 robfinch
                icstate <= IC6;
7784
        end
7785
IC6:  icstate <= IC7;
7786
IC7:    icstate <= IC8;
7787
IC8:    begin
7788
             icstate <= IDLE;
7789
             icnxt <= TRUE;
7790
        end
7791
default:     icstate <= IDLE;
7792
endcase
7793
 
7794 49 robfinch
if (mem1_available && dram0_load)
7795 48 robfinch
case(dram0)
7796
`DRAMSLOT_AVAIL:        ;
7797
`DRAMSLOT_BUSY:         dram0 <= dram0 + !dram0_unc;
7798
3'd2:                           dram0 <= dram0 + 3'd1;
7799
3'd3:                           dram0 <= dram0 + 3'd1;
7800
3'd4:                           if (dhit0) dram0 <= `DRAMREQ_READY; else dram0 <= `DRAMSLOT_REQBUS;
7801
`DRAMSLOT_REQBUS:       ;
7802
`DRAMSLOT_HASBUS:       ;
7803
`DRAMREQ_READY:         ;
7804
endcase
7805
 
7806 49 robfinch
if (mem2_available && dram1_load && `NUM_MEM > 1)
7807 48 robfinch
case(dram1)
7808
`DRAMSLOT_AVAIL:        ;
7809
`DRAMSLOT_BUSY:         dram1 <= dram1 + !dram1_unc;
7810
3'd2:                           dram1 <= dram1 + 3'd1;
7811
3'd3:                           dram1 <= dram1 + 3'd1;
7812
3'd4:                           if (dhit1) dram1 <= `DRAMREQ_READY; else dram1 <= `DRAMSLOT_REQBUS;
7813
`DRAMSLOT_REQBUS:       ;
7814
`DRAMSLOT_HASBUS:       ;
7815
`DRAMREQ_READY:         ;
7816
endcase
7817
 
7818 49 robfinch
if (mem3_available && dram2_load && `NUM_MEM > 2)
7819 48 robfinch
case(dram2)
7820
`DRAMSLOT_AVAIL:        ;
7821
`DRAMSLOT_BUSY:         dram2 <= dram2 + !dram2_unc;
7822
3'd2:                           dram2 <= dram2 + 3'd1;
7823
3'd3:                           dram2 <= dram2 + 3'd1;
7824
3'd4:                           if (dhit2) dram2 <= `DRAMREQ_READY; else dram2 <= `DRAMSLOT_REQBUS;
7825
`DRAMSLOT_REQBUS:       ;
7826
`DRAMSLOT_HASBUS:       ;
7827
`DRAMREQ_READY:         ;
7828
endcase
7829
 
7830
// Bus Interface Unit (BIU)
7831
// Interfaces to the external bus which is WISHBONE compatible.
7832
// Stores take precedence over other operations.
7833
// Next data cache read misses are serviced.
7834
// Uncached data reads are serviced.
7835
// Finally L2 instruction cache misses are serviced.
7836
 
7837
case(bstate)
7838
BIDLE:
7839 49 robfinch
        begin
7840
                isCAS <= FALSE;
7841
                isAMO <= FALSE;
7842
                isInc <= FALSE;
7843
                isSpt <= FALSE;
7844
                isRMW <= FALSE;
7845
                rdvq <= 1'b0;
7846
                errq <= 1'b0;
7847
                exvq <= 1'b0;
7848
                bwhich <= 2'b00;
7849
                preload <= FALSE;
7850
`ifdef HAS_WB
7851
                if (wb_v[0] & wb_en) begin
7852
                        cyc_o <= `HIGH;
7853
                        stb_o <= `HIGH;
7854
                        we_o <= `HIGH;
7855
                        sel_o <= wb_sel[0];
7856
                        adr_o <= wb_addr[0];
7857
                        dat_o <= wb_data[0];
7858
                        ol_o  <= wb_ol[0];
7859
                        wbo_id <= wb_id[0];
7860
                        bstate <= wb_rmw[0] ? B12 : B1;
7861
                end
7862
                begin
7863
                        for (j = 1; j < `WB_DEPTH; j = j + 1) begin
7864
                wb_v[j-1] <= wb_v[j];
7865
                wb_id[j-1] <= wb_id[j];
7866
                wb_rmw[j-1] <= wb_rmw[j];
7867
                wb_sel[j-1] <= wb_sel[j];
7868
                wb_addr[j-1] <= wb_addr[j];
7869
                wb_data[j-1] <= wb_data[j];
7870
                wb_ol[j-1] <= wb_ol[j];
7871
        end
7872
        wb_v[`WB_DEPTH-1] <= `INV;
7873
        wb_rmw[`WB_DEPTH-1] <= `FALSE;
7874
    end
7875
 
7876
//                      if (|wb_v)
7877
//                              ;
7878
 //       else
7879
`endif
7880
      if (~|wb_v && mem1_available && dram0==`DRAMSLOT_BUSY && dram0_rmw) begin
7881 48 robfinch
`ifdef SUPPORT_DBG
7882
            if (dbg_smatch0|dbg_lmatch0) begin
7883
                 dramA_v <= `TRUE;
7884
                 dramA_id <= dram0_id;
7885
                 dramA_exc <= `FLT_DBG;
7886
                 dramA_bus <= 64'h0;
7887
                 dram0 <= `DRAMSLOT_AVAIL;
7888
            end
7889
            else
7890
`endif
7891
            begin
7892
                 isRMW <= dram0_rmw;
7893
                 isCAS <= IsCAS(dram0_instr);
7894
                 isAMO <= IsAMO(dram0_instr);
7895
                 isInc <= IsInc(dram0_instr);
7896
                 casid <= dram0_id;
7897
                 bwhich <= 2'b00;
7898 49 robfinch
                 dram0 <= `DRAMSLOT_HASBUS;
7899 48 robfinch
                 cyc_o <= `HIGH;
7900
                 stb_o <= `HIGH;
7901
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
7902
                 adr_o <= dram0_addr;
7903
                 dat_o <= fnDato(dram0_instr,dram0_data);
7904
                 ol_o  <= dram0_ol;
7905
                 bstate <= B12;
7906
            end
7907
        end
7908 49 robfinch
        else if (~|wb_v && mem2_available && dram1==`DRAMSLOT_BUSY && dram1_rmw && `NUM_MEM > 1) begin
7909 48 robfinch
`ifdef SUPPORT_DBG
7910
            if (dbg_smatch1|dbg_lmatch1) begin
7911
                 dramB_v <= `TRUE;
7912
                 dramB_id <= dram1_id;
7913
                 dramB_exc <= `FLT_DBG;
7914
                 dramB_bus <= 64'h0;
7915
                 dram1 <= `DRAMSLOT_AVAIL;
7916
            end
7917
            else
7918
`endif
7919
            begin
7920
                 isRMW <= dram1_rmw;
7921
                 isCAS <= IsCAS(dram1_instr);
7922
                 isAMO <= IsAMO(dram1_instr);
7923
                 isInc <= IsInc(dram1_instr);
7924
                 casid <= dram1_id;
7925
                 bwhich <= 2'b01;
7926 49 robfinch
                 dram1 <= `DRAMSLOT_HASBUS;
7927 48 robfinch
                 cyc_o <= `HIGH;
7928
                 stb_o <= `HIGH;
7929
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
7930
                 adr_o <= dram1_addr;
7931
                 dat_o <= fnDato(dram1_instr,dram1_data);
7932
                 ol_o  <= dram1_ol;
7933
                 bstate <= B12;
7934
            end
7935
        end
7936 49 robfinch
        else if (~|wb_v && mem3_available && dram2==`DRAMSLOT_BUSY && dram2_rmw && `NUM_MEM > 2) begin
7937 48 robfinch
`ifdef SUPPORT_DBG
7938
            if (dbg_smatch2|dbg_lmatch2) begin
7939
                 dramC_v <= `TRUE;
7940
                 dramC_id <= dram2_id;
7941
                 dramC_exc <= `FLT_DBG;
7942
                 dramC_bus <= 64'h0;
7943
                 dram2 <= `DRAMSLOT_AVAIL;
7944
            end
7945
            else
7946
`endif
7947
            begin
7948
                 isRMW <= dram2_rmw;
7949
                 isCAS <= IsCAS(dram2_instr);
7950
                 isAMO <= IsAMO(dram2_instr);
7951
                 isInc <= IsInc(dram2_instr);
7952
                 casid <= dram2_id;
7953
                 bwhich <= 2'b10;
7954 49 robfinch
                 dram2 <= `DRAMSLOT_HASBUS;
7955 48 robfinch
                 cyc_o <= `HIGH;
7956
                 stb_o <= `HIGH;
7957
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
7958
                 adr_o <= dram2_addr;
7959
                 dat_o <= fnDato(dram2_instr,dram2_data);
7960
                 ol_o  <= dram2_ol;
7961
                 bstate <= B12;
7962
            end
7963
        end
7964 50 robfinch
        else if (mem1_available && dram0==`DRAMSLOT_BUSY && dram0_store) begin
7965 48 robfinch
`ifdef SUPPORT_DBG
7966
            if (dbg_smatch0) begin
7967
                 dramA_v <= `TRUE;
7968
                 dramA_id <= dram0_id;
7969
                 dramA_exc <= `FLT_DBG;
7970
                 dramA_bus <= 64'h0;
7971
                 dram0 <= `DRAMSLOT_AVAIL;
7972
            end
7973
            else
7974
`endif
7975
            begin
7976 49 robfinch
                                                        bwhich <= 2'b00;
7977
`ifndef HAS_WB
7978
                                                        dram0 <= `DRAMSLOT_HASBUS;
7979
                                                        dram0_instr[`INSTRUCTION_OP] <= `NOP;
7980
                 cyc_o <= `HIGH;
7981
                 stb_o <= `HIGH;
7982 48 robfinch
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
7983
                 adr_o <= dram0_addr;
7984
                 dat_o <= fnDato(dram0_instr,dram0_data);
7985
                 ol_o  <= dram0_ol;
7986
                 bstate <= B1;
7987 49 robfinch
`else
7988
                                                                if (wbptr<`WB_DEPTH-1) begin
7989
                                                                        dram0 <= `DRAMREQ_READY;
7990
                                                                        dram0_instr[`INSTRUCTION_OP] <= `NOP;
7991
                                                                        wb_update(
7992
                                                                                dram0_id,
7993
                                                                                `FALSE,
7994
                                                                                fnSelect(dram0_instr,dram0_addr),
7995
                                                                                dram0_ol,
7996
                                                                                dram0_addr,
7997
                                                                                fnDato(dram0_instr,dram0_data)
7998
                                                                        );
7999
                                                                        iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
8000
                                                                        iqentry_out[ dram0_id[`QBITS] ] <= `INV;
8001
                                                                end
8002
`endif
8003
//                 cr_o <= IsSWC(dram0_instr);
8004 48 robfinch
            end
8005
        end
8006 50 robfinch
        else if (mem2_available && dram1==`DRAMSLOT_BUSY && dram1_store && `NUM_MEM > 1) begin
8007 48 robfinch
`ifdef SUPPORT_DBG
8008
            if (dbg_smatch1) begin
8009
                 dramB_v <= `TRUE;
8010
                 dramB_id <= dram1_id;
8011
                 dramB_exc <= `FLT_DBG;
8012
                 dramB_bus <= 64'h0;
8013
                 dram1 <= `DRAMSLOT_AVAIL;
8014
            end
8015
            else
8016
`endif
8017
            begin
8018 49 robfinch
                 bwhich <= 2'b01;
8019
`ifndef HAS_WB
8020 48 robfinch
                 dram1 <= `DRAMSLOT_HASBUS;
8021
                 dram1_instr[`INSTRUCTION_OP] <= `NOP;
8022 49 robfinch
                 cyc_o <= `HIGH;
8023
                 stb_o <= `HIGH;
8024 48 robfinch
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
8025
                 adr_o <= dram1_addr;
8026
                 dat_o <= fnDato(dram1_instr,dram1_data);
8027
                 ol_o  <= dram1_ol;
8028
                 bstate <= B1;
8029 49 robfinch
`else
8030
                                                                if (wbptr<`WB_DEPTH-1) begin
8031
                                                                        dram1 <= `DRAMREQ_READY;
8032
                        dram1_instr[`INSTRUCTION_OP] <= `NOP;
8033
                                                                        wb_update(
8034
                                                                                dram1_id,
8035
                                                                                `FALSE,
8036
                                                                                fnSelect(dram1_instr,dram1_addr),
8037
                                                                                dram1_ol,
8038
                                                                                dram1_addr,
8039
                                                                                fnDato(dram1_instr,dram1_data)
8040
                                                                        );
8041
                                                                        iqentry_done[ dram1_id[`QBITS] ] <= `VAL;
8042
                                                                        iqentry_out[ dram1_id[`QBITS] ] <= `INV;
8043
                                                                end
8044
`endif
8045
//                 cr_o <= IsSWC(dram0_instr);
8046 48 robfinch
            end
8047
        end
8048 50 robfinch
        else if (mem3_available && dram2==`DRAMSLOT_BUSY && dram2_store && `NUM_MEM > 2) begin
8049 48 robfinch
`ifdef SUPPORT_DBG
8050
            if (dbg_smatch2) begin
8051
                 dramC_v <= `TRUE;
8052
                 dramC_id <= dram2_id;
8053
                 dramC_exc <= `FLT_DBG;
8054
                 dramC_bus <= 64'h0;
8055
                 dram2 <= `DRAMSLOT_AVAIL;
8056
            end
8057
            else
8058
`endif
8059
            begin
8060 49 robfinch
                 bwhich <= 2'b10;
8061
`ifndef HAS_WB
8062 48 robfinch
                 dram2 <= `DRAMSLOT_HASBUS;
8063
                 dram2_instr[`INSTRUCTION_OP] <= `NOP;
8064 49 robfinch
                 cyc_o <= `HIGH;
8065
                 stb_o <= `HIGH;
8066 48 robfinch
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
8067
                 adr_o <= dram2_addr;
8068
                 dat_o <= fnDato(dram2_instr,dram2_data);
8069
                 ol_o  <= dram2_ol;
8070
                 bstate <= B1;
8071 49 robfinch
`else
8072
                                                                if (wbptr<`WB_DEPTH-1) begin
8073
                                                                        dram2 <= `DRAMREQ_READY;
8074
                        dram2_instr[`INSTRUCTION_OP] <= `NOP;
8075
                                                                        wb_update(
8076
                                                                                dram2_id,
8077
                                                                                `FALSE,
8078
                                                                                fnSelect(dram2_instr,dram2_addr),
8079
                                                                                dram2_ol,
8080
                                                                                dram2_addr,
8081
                                                                                fnDato(dram2_instr,dram2_data)
8082
                                                                        );
8083
                                                                        iqentry_done[ dram2_id[`QBITS] ] <= `VAL;
8084
                                                                        iqentry_out[ dram2_id[`QBITS] ] <= `INV;
8085
                                                                end
8086
`endif
8087
//                 cr_o <= IsSWC(dram0_instr);
8088 48 robfinch
            end
8089
        end
8090
        // Check for read misses on the data cache
8091 49 robfinch
        else if (mem1_available && !dram0_unc && dram0==`DRAMSLOT_REQBUS && dram0_load) begin
8092 48 robfinch
`ifdef SUPPORT_DBG
8093
            if (dbg_lmatch0) begin
8094
                 dramA_v <= `TRUE;
8095
                 dramA_id <= dram0_id;
8096
                 dramA_exc <= `FLT_DBG;
8097
                 dramA_bus <= 64'h0;
8098
                 dram0 <= `DRAMSLOT_AVAIL;
8099
            end
8100
            else
8101
`endif
8102
            begin
8103
                 dram0 <= `DRAMSLOT_HASBUS;
8104
                 bwhich <= 2'b00;
8105
                 preload <= dram0_preload;
8106
                 bstate <= B2;
8107
            end
8108
        end
8109 49 robfinch
        else if (~|wb_v && mem2_available && !dram1_unc && dram1==`DRAMSLOT_REQBUS && dram1_load && `NUM_MEM > 1) begin
8110 48 robfinch
`ifdef SUPPORT_DBG
8111
            if (dbg_lmatch1) begin
8112
                 dramB_v <= `TRUE;
8113
                 dramB_id <= dram1_id;
8114
                 dramB_exc <= `FLT_DBG;
8115
                 dramB_bus <= 64'h0;
8116
                 dram1 <= `DRAMSLOT_AVAIL;
8117
            end
8118
            else
8119
`endif
8120
            begin
8121
                 dram1 <= `DRAMSLOT_HASBUS;
8122
                 bwhich <= 2'b01;
8123
                 preload <= dram1_preload;
8124
                 bstate <= B2;
8125
            end
8126
        end
8127 49 robfinch
        else if (~|wb_v && mem3_available && !dram2_unc && dram2==`DRAMSLOT_REQBUS && dram2_load && `NUM_MEM > 2) begin
8128 48 robfinch
`ifdef SUPPORT_DBG
8129
            if (dbg_lmatch2) begin
8130
                 dramC_v <= `TRUE;
8131
                 dramC_id <= dram2_id;
8132
                 dramC_exc <= `FLT_DBG;
8133
                 dramC_bus <= 64'h0;
8134
                 dram2 <= `DRAMSLOT_AVAIL;
8135
            end
8136
            else
8137
`endif
8138
            begin
8139
                 dram2 <= `DRAMSLOT_HASBUS;
8140
                 preload <= dram2_preload;
8141
                 bwhich <= 2'b10;
8142
                 bstate <= B2;
8143
            end
8144
        end
8145 49 robfinch
        else if (~|wb_v && mem1_available && dram0_unc && dram0==`DRAMSLOT_BUSY && dram0_load) begin
8146 48 robfinch
`ifdef SUPPORT_DBG
8147
            if (dbg_lmatch0) begin
8148
                 dramA_v <= `TRUE;
8149
                 dramA_id <= dram0_id;
8150
                 dramA_exc <= `FLT_DBG;
8151
                 dramA_bus <= 64'h0;
8152
                 dram0 <= `DRAMSLOT_AVAIL;
8153
            end
8154
            else
8155
`endif
8156
            begin
8157
                 bwhich <= 2'b00;
8158
                 cyc_o <= `HIGH;
8159
                 stb_o <= `HIGH;
8160
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
8161
                 adr_o <= {dram0_addr[31:3],3'b0};
8162
                 sr_o <=  IsLWR(dram0_instr);
8163
                 ol_o  <= dram0_ol;
8164
                 bstate <= B12;
8165
            end
8166
        end
8167 49 robfinch
        else if (~|wb_v && mem2_available && dram1_unc && dram1==`DRAMSLOT_BUSY && dram1_load && `NUM_MEM > 1) begin
8168 48 robfinch
`ifdef SUPPORT_DBG
8169
            if (dbg_lmatch1) begin
8170
                 dramB_v <= `TRUE;
8171
                 dramB_id <= dram1_id;
8172
                 dramB_exc <= `FLT_DBG;
8173
                 dramB_bus <= 64'h0;
8174
                 dram1 <= `DRAMSLOT_AVAIL;
8175
            end
8176
            else
8177
`endif
8178
            begin
8179
                 bwhich <= 2'b01;
8180
                 cyc_o <= `HIGH;
8181
                 stb_o <= `HIGH;
8182
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
8183
                 adr_o <= {dram1_addr[31:3],3'b0};
8184
                 sr_o <=  IsLWR(dram1_instr);
8185
                 ol_o  <= dram1_ol;
8186
                 bstate <= B12;
8187
            end
8188
        end
8189 49 robfinch
        else if (~|wb_v && mem3_available && dram2_unc && dram2==`DRAMSLOT_BUSY && dram2_load && `NUM_MEM > 2) begin
8190 48 robfinch
`ifdef SUPPORT_DBG
8191
            if (dbg_lmatch2) begin
8192
                 dramC_v <= `TRUE;
8193
                 dramC_id <= dram2_id;
8194
                 dramC_exc <= `FLT_DBG;
8195
                 dramC_bus <= 64'h0;
8196
                 dram2 <= 2'd0;
8197
            end
8198
            else
8199
`endif
8200
            begin
8201
                 bwhich <= 2'b10;
8202
                 cyc_o <= `HIGH;
8203
                 stb_o <= `HIGH;
8204
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
8205
                 adr_o <= {dram2_addr[31:3],3'b0};
8206
                 sr_o <=  IsLWR(dram2_instr);
8207
                 ol_o  <= dram2_ol;
8208
                 bstate <= B12;
8209
            end
8210
        end
8211
        // Check for L2 cache miss
8212 49 robfinch
        else if (~|wb_v && !ihitL2) begin
8213 48 robfinch
             cti_o <= 3'b001;
8214 49 robfinch
             bte_o <= 2'b00;//2'b01;    // 4 beat burst wrap
8215 48 robfinch
             cyc_o <= `HIGH;
8216
             stb_o <= `HIGH;
8217
             sel_o <= 8'hFF;
8218
             icl_o <= `HIGH;
8219 49 robfinch
             iccnt <= 3'd0;
8220 48 robfinch
//            adr_o <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
8221
//            L2_adr <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
8222
             adr_o <= {pcr[5:0],L1_adr[31:5],5'h0};
8223
             ol_o  <= ol[0];
8224
             L2_adr <= {pcr[5:0],L1_adr[31:5],5'h0};
8225
             L2_xsel <= 1'b0;
8226
             bstate <= B7;
8227
        end
8228
    end
8229
// Terminal state for a store operation.
8230 49 robfinch
// Note that if only a single memory channel is selected, bwhich will be a
8231
// constant 0. This should cause the extra code to be removed.
8232 48 robfinch
B1:
8233
    if (acki|err_i) begin
8234
         isStore <= `TRUE;
8235
         cyc_o <= `LOW;
8236
         stb_o <= `LOW;
8237
         we_o <= `LOW;
8238
         sel_o <= 8'h00;
8239
         cr_o <= 1'b0;
8240
        // This isn't a good way of doing things; the state should be propagated
8241
        // to the commit stage, however since this is a store we know there will
8242
        // be no change of program flow. So the reservation status bit is set
8243
        // here. The author wanted to avoid the complexity of propagating the
8244
        // input signal to the commit stage. It does mean that the SWC
8245
        // instruction should be surrounded by SYNC's.
8246
        if (cr_o)
8247
             sema[0] <= rbi_i;
8248 49 robfinch
`ifdef HAS_WB
8249
                                for (n = 0; n < QENTRIES; n = n + 1) begin
8250
                                        if (wbo_id[n]) begin
8251
                        iqentry_exc[n] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
8252
                        if (err_i|wrv_i) begin
8253
                                iqentry_a1[n] <= adr_o;
8254
                                wb_v <= 8'h00;          // Invalidate write buffer if there is a problem with the store
8255
                                wb_en <= `FALSE;        // and disable write buffer
8256
                        end
8257
                                                iqentry_cmt[n] <= `VAL;
8258
                                                iqentry_aq[n] <= `INV;
8259
                                        end
8260
                                end
8261
`else
8262 48 robfinch
        case(bwhich)
8263 49 robfinch
        2'd0:   if (mem1_available) begin
8264 48 robfinch
                 dram0 <= `DRAMREQ_READY;
8265
                 iqentry_exc[dram0_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
8266
                if (err_i|wrv_i)  iqentry_a1[dram0_id[`QBITS]] <= adr_o;
8267 49 robfinch
                                                                        iqentry_cmt[ dram0_id[`QBITS] ] <= `VAL;
8268
                                                                        iqentry_aq[ dram0_id[`QBITS] ] <= `INV;
8269 48 robfinch
                        //iqentry_out[ dram0_id[`QBITS] ] <= `INV;
8270
                end
8271 49 robfinch
        2'd1:   if (`NUM_MEM > 1) begin
8272 48 robfinch
                 dram1 <= `DRAMREQ_READY;
8273
                 iqentry_exc[dram1_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
8274
                if (err_i|wrv_i)  iqentry_a1[dram1_id[`QBITS]] <= adr_o;
8275 49 robfinch
                                                                        iqentry_cmt[ dram1_id[`QBITS] ] <= `VAL;
8276
                                                                        iqentry_aq[ dram1_id[`QBITS] ] <= `INV;
8277 48 robfinch
                        //iqentry_out[ dram1_id[`QBITS] ] <= `INV;
8278
                end
8279 49 robfinch
        2'd2:   if (`NUM_MEM > 2) begin
8280 48 robfinch
                 dram2 <= `DRAMREQ_READY;
8281
                 iqentry_exc[dram2_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
8282
                if (err_i|wrv_i)  iqentry_a1[dram2_id[`QBITS]] <= adr_o;
8283 49 robfinch
                                                                        iqentry_cmt[ dram2_id[`QBITS] ] <= `VAL;
8284
                                                                        iqentry_aq[ dram2_id[`QBITS] ] <= `INV;
8285 48 robfinch
                        //iqentry_out[ dram2_id[`QBITS] ] <= `INV;
8286
                end
8287
        default:    ;
8288
        endcase
8289 49 robfinch
`endif
8290 48 robfinch
         bstate <= B19;
8291
    end
8292
B2:
8293
    begin
8294
    dccnt <= 2'd0;
8295
    case(bwhich)
8296
    2'd0:   begin
8297
             cti_o <= 3'b001;
8298
             bte_o <= 2'b01;
8299
             cyc_o <= `HIGH;
8300
             stb_o <= `HIGH;
8301
             sel_o <= fnSelect(dram0_instr,dram0_addr);
8302
             adr_o <= {dram0_addr[31:5],5'b0};
8303
             ol_o  <= dram0_ol;
8304
             bstate <= B2d;
8305
            end
8306 49 robfinch
    2'd1:   if (`NUM_MEM > 1) begin
8307 48 robfinch
             cti_o <= 3'b001;
8308
             bte_o <= 2'b01;
8309
             cyc_o <= `HIGH;
8310
             stb_o <= `HIGH;
8311
             sel_o <= fnSelect(dram1_instr,dram1_addr);
8312
             adr_o <= {dram1_addr[31:5],5'b0};
8313
             ol_o  <= dram1_ol;
8314
             bstate <= B2d;
8315
            end
8316 49 robfinch
    2'd2:   if (`NUM_MEM > 2) begin
8317 48 robfinch
             cti_o <= 3'b001;
8318
             bte_o <= 2'b01;
8319
             cyc_o <= `HIGH;
8320
             stb_o <= `HIGH;
8321
             sel_o <= fnSelect(dram2_instr,dram2_addr);
8322
             adr_o <= {dram2_addr[31:5],5'b0};
8323
             ol_o  <= dram2_ol;
8324
             bstate <= B2d;
8325
            end
8326
    default:    if (~acki)  bstate <= BIDLE;
8327
    endcase
8328
    end
8329
// Data cache load terminal state
8330
B2d:
8331
    if (ack_i|err_i) begin
8332
        errq <= errq | err_i;
8333
        rdvq <= rdvq | rdv_i;
8334
        if (!preload)   // A preload instruction ignores any error
8335
        case(bwhich)
8336
        2'd0:   if (err_i|rdv_i) begin
8337
                     iqentry_a1[dram0_id[`QBITS]] <= adr_o;
8338
                     iqentry_exc[dram0_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
8339
                end
8340 49 robfinch
        2'd1:   if ((err_i|rdv_i) && `NUM_MEM > 1) begin
8341 48 robfinch
                     iqentry_a1[dram1_id[`QBITS]] <= adr_o;
8342
                     iqentry_exc[dram1_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
8343
                end
8344 49 robfinch
        2'd2:   if ((err_i|rdv_i) && `NUM_MEM > 2) begin
8345 48 robfinch
                     iqentry_a1[dram2_id[`QBITS]] <= adr_o;
8346
                     iqentry_exc[dram2_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
8347
                end
8348
        default:    ;
8349
        endcase
8350
        dccnt <= dccnt + 2'd1;
8351
        adr_o[4:3] <= adr_o[4:3] + 2'd1;
8352
        bstate <= B2d;
8353
        if (dccnt==2'd2)
8354
             cti_o <= 3'b111;
8355
        if (dccnt==2'd3) begin
8356
             cti_o <= 3'b000;
8357
             bte_o <= 2'b00;
8358
             cyc_o <= `LOW;
8359
             stb_o <= `LOW;
8360
             sel_o <= 8'h00;
8361
             bstate <= B4;
8362
        end
8363
    end
8364
B3: begin
8365
         stb_o <= `HIGH;
8366
         bstate <= B2d;
8367
    end
8368
B4:  bstate <= B5;
8369
B5:  bstate <= B6;
8370
B6: begin
8371
    case(bwhich)
8372
    2'd0:    dram0 <= `DRAMSLOT_BUSY;  // causes retest of dhit
8373
    2'd1:    dram1 <= `DRAMSLOT_BUSY;
8374
    2'd2:    dram2 <= `DRAMSLOT_BUSY;
8375
    default:    ;
8376
    endcase
8377
    if (~ack_i)  bstate <= BIDLE;
8378
    end
8379
 
8380
// Ack state for instruction cache load
8381
B7:
8382
    if (ack_i|err_i) begin
8383
        errq <= errq | err_i;
8384
        exvq <= exvq | exv_i;
8385 49 robfinch
//        L1_en <= 9'h3 << {L2_xsel,L2_adr[4:3],1'b0};
8386 48 robfinch
//        L1_wr0 <= `TRUE;
8387
//        L1_wr1 <= `TRUE;
8388
//        L1_adr <= L2_adr;
8389
        if (err_i)
8390 49 robfinch
                L2_rdat <= {9{11'b0,4'd7,1'b0,`FLT_IBE,2'b00,`BRK}};
8391 48 robfinch
        else
8392 49 robfinch
                L2_rdat <= {dat_i[31:0],{4{dat_i}}};
8393 48 robfinch
        iccnt <= iccnt + 3'd1;
8394
        //stb_o <= `LOW;
8395
        if (iccnt==3'd3)
8396
            cti_o <= 3'b111;
8397
        if (iccnt==3'd4) begin
8398
            cti_o <= 3'b000;
8399
            bte_o <= 2'b00;             // linear burst
8400
            cyc_o <= `LOW;
8401
            stb_o <= `LOW;
8402
            sel_o <= 8'h00;
8403
            icl_o <= `LOW;
8404
            bstate <= B9;
8405
        end
8406
        else begin
8407
            L2_adr[4:3] <= L2_adr[4:3] + 2'd1;
8408
            if (L2_adr[4:3]==2'b11)
8409
                L2_xsel <= 1'b1;
8410
        end
8411
    end
8412
B9:
8413
        begin
8414
                L1_wr0 <= `FALSE;
8415
                L1_wr1 <= `FALSE;
8416 49 robfinch
                L1_wr2 <= `FALSE;
8417
                L1_en <= 9'h1FF;
8418 48 robfinch
                L2_xsel <= 1'b0;
8419
                if (~ack_i) begin
8420
                        bstate <= BIDLE;
8421
                        L2_nxt <= TRUE;
8422
                end
8423
        end
8424
B12:
8425
    if (ack_i|err_i) begin
8426
        if (isCAS) begin
8427
             iqentry_res        [ casid[`QBITS] ] <= (dat_i == cas);
8428
             iqentry_exc [ casid[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8429
             iqentry_done[ casid[`QBITS] ] <= `VAL;
8430
             iqentry_instr[ casid[`QBITS]] <= `NOP_INSN;
8431
             iqentry_out [ casid[`QBITS] ] <= `INV;
8432
            if (err_i | rdv_i) iqentry_a1[casid[`QBITS]] <= adr_o;
8433
            if (dat_i == cas) begin
8434
                 stb_o <= `LOW;
8435
                 we_o <= `TRUE;
8436
                 bstate <= B15;
8437
            end
8438
            else begin
8439
                 cas <= dat_i;
8440
                 cyc_o <= `LOW;
8441
                 stb_o <= `LOW;
8442
                 sel_o <= 8'h00;
8443
                case(bwhich)
8444
                2'b00:   dram0 <= `DRAMREQ_READY;
8445
                2'b01:   dram1 <= `DRAMREQ_READY;
8446
                2'b10:   dram2 <= `DRAMREQ_READY;
8447
                default:    ;
8448
                endcase
8449
                 bstate <= B19;
8450
            end
8451
        end
8452
        else if (isRMW) begin
8453
             rmw_instr <= iqentry_instr[casid[`QBITS]];
8454
             rmw_argA <= dat_i;
8455
                 if (isSpt) begin
8456
                        rmw_argB <= 64'd1 << iqentry_a1[casid[`QBITS]][63:58];
8457
                        rmw_argC <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ?
8458
                                                iqentry_a3[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58] :
8459
                                                iqentry_a2[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58];
8460
                 end
8461
                 else if (isInc) begin
8462
                        rmw_argB <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ? {{59{iqentry_instr[casid[`QBITS]][22]}},iqentry_instr[casid[`QBITS]][22:18]} :
8463
                                                                                                                                 {{59{iqentry_instr[casid[`QBITS]][17]}},iqentry_instr[casid[`QBITS]][17:13]};
8464
                 end
8465
                 else begin // isAMO
8466
                     iqentry_res [ casid[`QBITS] ] <= dat_i;
8467
                     rmw_argB <= iqentry_instr[casid[`QBITS]][31] ? {{59{iqentry_instr[casid[`QBITS]][20:16]}},iqentry_instr[casid[`QBITS]][20:16]} : iqentry_a2[casid[`QBITS]];
8468
                 end
8469
             iqentry_exc [ casid[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8470
             if (err_i | rdv_i) iqentry_a1[casid[`QBITS]] <= adr_o;
8471
             stb_o <= `LOW;
8472
             bstate <= B20;
8473
                end
8474
        else begin
8475
             cyc_o <= `LOW;
8476
             stb_o <= `LOW;
8477
             sel_o <= 8'h00;
8478
             sr_o <= `LOW;
8479
             xdati <= dat_i;
8480
            case(bwhich)
8481
            2'b00:  begin
8482
                     dram0 <= `DRAMREQ_READY;
8483
                     iqentry_exc [ dram0_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8484
                    if (err_i|rdv_i)  iqentry_a1[dram0_id[`QBITS]] <= adr_o;
8485
                    end
8486 49 robfinch
            2'b01:  if (`NUM_MEM > 1) begin
8487 48 robfinch
                     dram1 <= `DRAMREQ_READY;
8488
                     iqentry_exc [ dram1_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8489
                    if (err_i|rdv_i)  iqentry_a1[dram1_id[`QBITS]] <= adr_o;
8490
                    end
8491 49 robfinch
            2'b10:  if (`NUM_MEM > 2) begin
8492 48 robfinch
                     dram2 <= `DRAMREQ_READY;
8493
                     iqentry_exc [ dram2_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8494
                    if (err_i|rdv_i)  iqentry_a1[dram2_id[`QBITS]] <= adr_o;
8495
                    end
8496
            default:    ;
8497
            endcase
8498
             bstate <= B19;
8499
        end
8500
    end
8501
// Three cycles to detemrine if there's a cache hit during a store.
8502
B16:    begin
8503
            case(bwhich)
8504
            2'd0:      if (dhit0) begin  dram0 <= `DRAMREQ_READY; bstate <= B17; end
8505
            2'd1:      if (dhit1) begin  dram1 <= `DRAMREQ_READY; bstate <= B17; end
8506
            2'd2:      if (dhit2) begin  dram2 <= `DRAMREQ_READY; bstate <= B17; end
8507
            default:    bstate <= BIDLE;
8508
            endcase
8509
            end
8510
B17:     bstate <= B18;
8511
B18:     bstate <= B19;
8512
B19:    if (~acki)  begin bstate <= BIDLE; isStore <= `FALSE; end
8513
B20:
8514
        if (~ack_i) begin
8515
                stb_o <= `HIGH;
8516
                we_o  <= `HIGH;
8517
                dat_o <= fnDato(rmw_instr,rmw_res);
8518
                bstate <= B1;
8519
        end
8520
B21:
8521
        if (~ack_i) begin
8522
                stb_o <= `HIGH;
8523
                bstate <= B12;
8524
        end
8525
default:     bstate <= BIDLE;
8526
endcase
8527
 
8528
if (!branchmiss) begin
8529
    case({fetchbuf0_v, fetchbuf1_v})
8530
    2'b00:  ;
8531
    2'b01:
8532
        if (canq1) begin
8533
                tail0 <= idp1(tail0);
8534
                tail1 <= idp1(tail1);
8535
        end
8536
    2'b10:
8537
        if (canq1) begin
8538
            tail0 <= idp1(tail0);
8539
            tail1 <= idp1(tail1);
8540
        end
8541
    2'b11:
8542
        if (canq1) begin
8543
            if (IsBranch(fetchbuf0_instr) && predict_taken0 && fetchbuf0_thrd==fetchbuf1_thrd) begin
8544
                 tail0 <= idp1(tail0);
8545
                 tail1 <= idp1(tail1);
8546
            end
8547
            else begin
8548
                                if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
8549
                        if (canq2) begin
8550
                             tail0 <= idp2(tail0);
8551
                             tail1 <= idp2(tail1);
8552
                        end
8553
                        else begin    // queued1 will be true
8554
                             tail0 <= idp1(tail0);
8555
                             tail1 <= idp1(tail1);
8556
                        end
8557
                end
8558
            end
8559
        end
8560
    endcase
8561
end
8562
`ifndef SUPPORT_SMT
8563
else begin      // if branchmiss
8564
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
8565
         tail0 <= 3'd0;
8566
         tail1 <= 3'd1;
8567
    end
8568
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
8569
         tail0 <= 3'd1;
8570
         tail1 <= 3'd2;
8571
    end
8572
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
8573
         tail0 <= 3'd2;
8574
         tail1 <= 3'd3;
8575
    end
8576
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
8577
         tail0 <= 3'd3;
8578
         tail1 <= 3'd4;
8579
    end
8580
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
8581
         tail0 <= 3'd4;
8582
         tail1 <= 3'd5;
8583
    end
8584
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
8585
         tail0 <= 3'd5;
8586
         tail1 <= 3'd6;
8587
    end
8588
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
8589
         tail0 <= 3'd6;
8590
         tail1 <= 3'd7;
8591
    end
8592
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
8593
         tail0 <= 3'd7;
8594
         tail1 <= 3'd0;
8595
    end
8596
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
8597
end
8598
`endif
8599
/*
8600
    if (pebm)
8601
         seq_num <= seq_num + 5'd3;
8602
    else if (queued2)
8603
         seq_num <= seq_num + 5'd2;
8604
    else if (queued1)
8605
         seq_num <= seq_num + 5'd1;
8606
*/
8607
//      #5 rf[0] = 0; rf_v[0] = 1; rf_source[0] = 0;
8608
        $display("\n\n\n\n\n\n\n\n");
8609
        $display("TIME %0d", $time);
8610
        $display("%h #", pc0);
8611
`ifdef SUPPORT_SMT
8612
    $display ("Regfile: %d", rgs[0]);
8613
        for (n=0; n < 32; n=n+4) begin
8614
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8615
               n[4:0]+0, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8616
               n[4:0]+1, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8617
               n[4:0]+2, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8618
               n[4:0]+3, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8619
               );
8620
        end
8621
    $display ("Regfile: %d", rgs[1]);
8622
        for (n=128; n < 160; n=n+4) begin
8623
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8624
               n[4:0]+0, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8625
               n[4:0]+1, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8626
               n[4:0]+2, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8627
               n[4:0]+3, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8628
               );
8629
        end
8630
`else
8631
    $display ("Regfile: %d", rgs);
8632
        for (n=0; n < 32; n=n+4) begin
8633
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8634
               n[4:0]+0, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8635
               n[4:0]+1, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8636
               n[4:0]+2, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8637
               n[4:0]+3, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8638
               );
8639
        end
8640
`endif
8641 49 robfinch
`ifdef FCU_ENH
8642 48 robfinch
        $display("Call Stack:");
8643 49 robfinch
        for (n = 0; n < 16; n = n + 4)
8644 48 robfinch
                $display("%c%d: %h   %c%d: %h   %c%d: %h   %c%d: %h",
8645
                        ufb1.ursb1.rasp==n+0 ?">" : " ", n[4:0]+0, ufb1.ursb1.ras[n+0],
8646
                        ufb1.ursb1.rasp==n+1 ?">" : " ", n[4:0]+1, ufb1.ursb1.ras[n+1],
8647
                        ufb1.ursb1.rasp==n+2 ?">" : " ", n[4:0]+2, ufb1.ursb1.ras[n+2],
8648
                        ufb1.ursb1.rasp==n+3 ?">" : " ", n[4:0]+3, ufb1.ursb1.ras[n+3]
8649
                );
8650
        $display("\n");
8651 49 robfinch
`endif
8652 48 robfinch
//    $display("Return address stack:");
8653
//    for (n = 0; n < 16; n = n + 1)
8654
//        $display("%d %h", rasp+n[3:0], ras[rasp+n[3:0]]);
8655
        $display("TakeBr:%d #", take_branch);//, backpc);
8656
        $display("%c%c A: %d %h %h #",
8657
            45, fetchbuf?45:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc);
8658
        $display("%c%c B: %d %h %h #",
8659
            45, fetchbuf?45:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc);
8660
        $display("%c%c C: %d %h %h #",
8661
            45, fetchbuf?62:45, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
8662
        $display("%c%c D: %d %h %h #",
8663
            45, fetchbuf?62:45, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
8664
 
8665
        for (i=0; i<QENTRIES; i=i+1)
8666
            $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#",
8667
                 (i[`QBITS]==head0)?"C":".",
8668
                 (i[`QBITS]==tail0)?"Q":".",
8669
                  i[`QBITS],
8670
                 iqentry_v[i] ? "v" : "-",
8671
                 iqentry_iv[i] ? "I" : "-",
8672
                 iqentry_done[i]?"d":"-",
8673
                 iqentry_out[i]?"o":"-",
8674
                 iqentry_bt[i],
8675
                 iqentry_memissue[i],
8676
                 iqentry_agen[i] ? "a": "-",
8677
                 iqentry_alu0_issue[i]?"0":iqentry_alu1_issue[i]?"1":"-",
8678
                 iqentry_stomp[i]?"s":"-",
8679
                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",
8680
                iqentry_instr[i], iqentry_tgt[i][4:0],
8681
                iqentry_exc[i], iqentry_res[i], iqentry_a0[i], iqentry_a1[i], iqentry_a1_v[i],
8682
                iqentry_a1_s[i],
8683
                iqentry_a2[i], iqentry_a2_v[i], iqentry_a2_s[i],
8684
                iqentry_a3[i], iqentry_a3_v[i], iqentry_a3_s[i],
8685
                iqentry_thrd[i],
8686
                iqentry_pc[i],
8687
                iqentry_sn[i], iqentry_ven[i]
8688
                );
8689
    $display("DRAM");
8690
        $display("%d %h %h %c%h %o #",
8691
            dram0, dram0_addr, dram0_data, (IsFlowCtrl(dram0_instr) ? 98 : (IsMem(dram0_instr)) ? 109 : 97),
8692
            dram0_instr, dram0_id);
8693 49 robfinch
          if (`NUM_MEM > 1)
8694 48 robfinch
        $display("%d %h %h %c%h %o #",
8695
            dram1, dram1_addr, dram1_data, (IsFlowCtrl(dram1_instr) ? 98 : (IsMem(dram1_instr)) ? 109 : 97),
8696
            dram1_instr, dram1_id);
8697 49 robfinch
          if (`NUM_MEM > 2)
8698 48 robfinch
        $display("%d %h %h %c%h %o #",
8699
            dram2, dram2_addr, dram2_data, (IsFlowCtrl(dram2_instr) ? 98 : (IsMem(dram2_instr)) ? 109 : 97),
8700
            dram2_instr, dram2_id);
8701
        $display("%d %h %o %h #", dramA_v, dramA_bus, dramA_id, dramA_exc);
8702 49 robfinch
        if (`NUM_MEM > 1)
8703 48 robfinch
        $display("%d %h %o %h #", dramB_v, dramB_bus, dramB_id, dramB_exc);
8704 49 robfinch
        if (`NUM_MEM > 2)
8705 48 robfinch
        $display("%d %h %o %h #", dramC_v, dramC_bus, dramC_id, dramC_exc);
8706
    $display("ALU");
8707
        $display("%d %h %h %h %c%h %d %o %h #",
8708
                alu0_dataready, alu0_argI, alu0_argA, alu0_argB,
8709
                 (IsFlowCtrl(alu0_instr) ? 98 : IsMem(alu0_instr) ? 109 : 97),
8710
                alu0_instr, alu0_bt, alu0_sourceid, alu0_pc);
8711
        $display("%d %h %o 0 #", alu0_v, alu0_bus, alu0_id);
8712 49 robfinch
        if (`NUM_ALU > 1) begin
8713
                $display("%d %h %h %h %c%h %d %o %h #",
8714
                        alu1_dataready, alu1_argI, alu1_argA, alu1_argB,
8715
                        (IsFlowCtrl(alu1_instr) ? 98 : IsMem(alu1_instr) ? 109 : 97),
8716
                        alu1_instr, alu1_bt, alu1_sourceid, alu1_pc);
8717
                $display("%d %h %o 0 #", alu1_v, alu1_bus, alu1_id);
8718
        end
8719 48 robfinch
        $display("FCU");
8720
        $display("%d %h %h %h %h #", fcu_v, fcu_bus, fcu_argI, fcu_argA, fcu_argB);
8721
        $display("%c %h %h #", fcu_branchmiss?"m":" ", fcu_sourceid, fcu_misspc);
8722
    $display("Commit");
8723
        $display("0: %c %h %o %d #", commit0_v?"v":" ", commit0_bus, commit0_id, commit0_tgt[4:0]);
8724
        $display("1: %c %h %o %d #", commit1_v?"v":" ", commit1_bus, commit1_id, commit1_tgt[4:0]);
8725
    $display("instructions committed: %d ticks: %d ", I, tick);
8726 49 robfinch
    $display("Write merges: %d", wb_merges);
8727 48 robfinch
 
8728
//
8729
//      $display("\n\n\n\n\n\n\n\n");
8730
//      $display("TIME %0d", $time);
8731
//      $display("  pc0=%h", pc0);
8732
//      $display("  pc1=%h", pc1);
8733
//      $display("  reg0=%h, v=%d, src=%o", rf[0], rf_v[0], rf_source[0]);
8734
//      $display("  reg1=%h, v=%d, src=%o", rf[1], rf_v[1], rf_source[1]);
8735
//      $display("  reg2=%h, v=%d, src=%o", rf[2], rf_v[2], rf_source[2]);
8736
//      $display("  reg3=%h, v=%d, src=%o", rf[3], rf_v[3], rf_source[3]);
8737
//      $display("  reg4=%h, v=%d, src=%o", rf[4], rf_v[4], rf_source[4]);
8738
//      $display("  reg5=%h, v=%d, src=%o", rf[5], rf_v[5], rf_source[5]);
8739
//      $display("  reg6=%h, v=%d, src=%o", rf[6], rf_v[6], rf_source[6]);
8740
//      $display("  reg7=%h, v=%d, src=%o", rf[7], rf_v[7], rf_source[7]);
8741
 
8742
//      $display("Fetch Buffers:");
8743
//      $display("  %c%c fbA: v=%d instr=%h pc=%h     %c%c fbC: v=%d instr=%h pc=%h", 
8744
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc,
8745
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
8746
//      $display("  %c%c fbB: v=%d instr=%h pc=%h     %c%c fbD: v=%d instr=%h pc=%h", 
8747
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc,
8748
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
8749
//      $display("  branchback=%d backpc=%h", branchback, backpc);
8750
 
8751
//      $display("Instruction Queue:");
8752
//      for (i=0; i<8; i=i+1) 
8753
//          $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",
8754
//              (i[`QBITS]==head0)?72:32, (i[`QBITS]==tail0)?84:32, i,
8755
//              iqentry_v[i], iqentry_done[i], iqentry_out[i], iqentry_agen[i], iqentry_res[i], iqentry_op[i], 
8756
//              iqentry_bt[i], iqentry_tgt[i], iqentry_a1[i], iqentry_a1_v[i], iqentry_a1_s[i], iqentry_a2[i], iqentry_a2_v[i], 
8757
//              iqentry_a2_s[i], iqentry_a0[i], iqentry_pc[i], iqentry_exc[i]);
8758
 
8759
//      $display("Scheduling Status:");
8760
//      $display("  iqentry0 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8761
//              iqentry_0_issue, iqentry_0_islot, iqentry_stomp[0], iqentry_source[0], iqentry_memready[0], iqentry_memissue[0]);
8762
//      $display("  iqentry1 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8763
//              iqentry_1_issue, iqentry_1_islot, iqentry_stomp[1], iqentry_source[1], iqentry_memready[1], iqentry_memissue[1]);
8764
//      $display("  iqentry2 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8765
//              iqentry_2_issue, iqentry_2_islot, iqentry_stomp[2], iqentry_source[2], iqentry_memready[2], iqentry_memissue[2]);
8766
//      $display("  iqentry3 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8767
//              iqentry_3_issue, iqentry_3_islot, iqentry_stomp[3], iqentry_source[3], iqentry_memready[3], iqentry_memissue[3]);
8768
//      $display("  iqentry4 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8769
//              iqentry_4_issue, iqentry_4_islot, iqentry_stomp[4], iqentry_source[4], iqentry_memready[4], iqentry_memissue[4]);
8770
//      $display("  iqentry5 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8771
//              iqentry_5_issue, iqentry_5_islot, iqentry_stomp[5], iqentry_source[5], iqentry_memready[5], iqentry_memissue[5]);
8772
//      $display("  iqentry6 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8773
//              iqentry_6_issue, iqentry_6_islot, iqentry_stomp[6], iqentry_source[6], iqentry_memready[6], iqentry_memissue[6]);
8774
//      $display("  iqentry7 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8775
//              iqentry_7_issue, iqentry_7_islot, iqentry_stomp[7], iqentry_source[7], iqentry_memready[7], iqentry_memissue[7]);
8776
 
8777
//      $display("ALU Inputs:");
8778
//      $display("  0: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
8779
//              alu0_available, alu0_dataready, alu0_sourceid, alu0_op, alu0_argA,
8780
//              alu0_argB, alu0_argI, alu0_bt);
8781
//      $display("  1: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
8782
//              alu1_available, alu1_dataready, alu1_sourceid, alu1_op, alu1_argA,
8783
//              alu1_argB, alu1_argI, alu1_bt);
8784
 
8785
//      $display("ALU Outputs:");
8786
//      $display("  0: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
8787
//              alu0_v, alu0_bus, alu0_id, alu0_branchmiss, alu0_misspc, alu0_sourceid);
8788
//      $display("  1: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
8789
//              alu1_v, alu1_bus, alu1_id, alu1_branchmiss, alu1_misspc, alu1_sourceid);
8790
 
8791
//      $display("DRAM Status:");
8792
//      $display("  OUT: v=%d data=%h tgt=%d id=%o", dram_v, dram_bus, dram_tgt, dram_id);
8793
//      $display("  dram0: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
8794
//          dram0, dram0_addr, dram0_data, dram0_op, dram0_tgt, dram0_id);
8795
//      $display("  dram1: status=%h addr=%h data=%h op=%d tgt=%d id=%o", 
8796
//          dram1, dram1_addr, dram1_data, dram1_op, dram1_tgt, dram1_id);
8797
//      $display("  dram2: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
8798
//          dram2, dram2_addr, dram2_data, dram2_op, dram2_tgt, dram2_id);
8799
 
8800
//      $display("Commit Buses:");
8801
//      $display("  0: v=%d id=%o data=%h", commit0_v, commit0_id, commit0_bus);
8802
//      $display("  1: v=%d id=%o data=%h", commit1_v, commit1_id, commit1_bus);
8803
 
8804
//
8805
//      $display("Memory Contents:");
8806
//      for (j=0; j<64; j=j+16)
8807
//          $display("  %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h", 
8808
//              m[j+0], m[j+1], m[j+2], m[j+3], m[j+4], m[j+5], m[j+6], m[j+7],
8809
//              m[j+8], m[j+9], m[j+10], m[j+11], m[j+12], m[j+13], m[j+14], m[j+15]);
8810
 
8811
        $display("");
8812
 
8813
        if (|panic) begin
8814
            $display("");
8815
            $display("-----------------------------------------------------------------");
8816
            $display("-----------------------------------------------------------------");
8817
            $display("---------------     PANIC:%s     -----------------", message[panic]);
8818
            $display("-----------------------------------------------------------------");
8819
            $display("-----------------------------------------------------------------");
8820
            $display("");
8821
            $display("instructions committed: %d", I);
8822
            $display("total execution cycles: %d", $time / 10);
8823
            $display("");
8824
        end
8825
        if (|panic && ~outstanding_stores) begin
8826
            $finish;
8827
        end
8828
    for (n = 0; n < QENTRIES; n = n + 1)
8829
        if (branchmiss) begin
8830
            if (!setpred[n]) begin
8831
                 iqentry_instr[n][`INSTRUCTION_OP] <= `NOP;
8832
                 iqentry_done[n] <= `VAL;
8833
                 iqentry_cmt[n] <= `VAL;
8834
            end
8835
        end
8836
 
8837
        if (snr) begin
8838
                seq_num <= 32'd0;
8839
                seq_num1 <= 32'd0;
8840
        end
8841
end // clock domain
8842
/*
8843
always @(posedge clk)
8844
if (rst) begin
8845
     tail0 <= 3'd0;
8846
     tail1 <= 3'd1;
8847
end
8848
else begin
8849
if (!branchmiss) begin
8850
    case({fetchbuf0_v, fetchbuf1_v})
8851
    2'b00:  ;
8852
    2'b01:
8853
        if (canq1) begin
8854
             tail0 <= idp1(tail0);
8855
             tail1 <= idp1(tail1);
8856
        end
8857
    2'b10:
8858
        if (canq1) begin
8859
             tail0 <= idp1(tail0);
8860
             tail1 <= idp1(tail1);
8861
        end
8862
    2'b11:
8863
        if (canq1) begin
8864
            if (IsBranch(fetchbuf0_instr) && predict_taken0) begin
8865
                 tail0 <= idp1(tail0);
8866
                 tail1 <= idp1(tail1);
8867
            end
8868
            else begin
8869
                                if (vqe < vl || !IsVector(fetchbuf0_instr)) begin
8870
                        if (canq2) begin
8871
                             tail0 <= idp2(tail0);
8872
                             tail1 <= idp2(tail1);
8873
                        end
8874
                        else begin    // queued1 will be true
8875
                             tail0 <= idp1(tail0);
8876
                             tail1 <= idp1(tail1);
8877
                        end
8878
                end
8879
            end
8880
        end
8881
    endcase
8882
end
8883
else begin      // if branchmiss
8884
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
8885
         tail0 <= 3'd0;
8886
         tail1 <= 3'd1;
8887
    end
8888
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
8889
         tail0 <= 3'd1;
8890
         tail1 <= 3'd2;
8891
    end
8892
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
8893
         tail0 <= 3'd2;
8894
         tail1 <= 3'd3;
8895
    end
8896
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
8897
         tail0 <= 3'd3;
8898
         tail1 <= 3'd4;
8899
    end
8900
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
8901
         tail0 <= 3'd4;
8902
         tail1 <= 3'd5;
8903
    end
8904
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
8905
         tail0 <= 3'd5;
8906
         tail1 <= 3'd6;
8907
    end
8908
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
8909
         tail0 <= 3'd6;
8910
         tail1 <= 3'd7;
8911
    end
8912
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
8913
         tail0 <= 3'd7;
8914
         tail1 <= 3'd0;
8915
    end
8916
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
8917
end
8918
end
8919
*/
8920
/*
8921
always @(posedge clk)
8922
if (rst)
8923
     seq_num <= 5'd0;
8924
else begin
8925
    if (pebm)
8926
         seq_num <= seq_num + 5'd3;
8927
    else if (queued2)
8928
         seq_num <= seq_num + 5'd2;
8929
    else if (queued1)
8930
         seq_num <= seq_num + 5'd1;
8931
end
8932
*/
8933 49 robfinch
 
8934
task wb_update;
8935
input [`QBITS] id;
8936
input rmw;
8937
input [7:0] sel;
8938
input [1:0] ol;
8939
input [`ABITS] addr;
8940
input [63:0] data;
8941
begin
8942
        if (wbptr > 0 && wb_addr[wbptr-1][AMSB:3]==addr[AMSB:3] && wb_ol[wbptr-1]==ol && wb_rmw[wbptr-1]==rmw) begin
8943
                wb_sel[wbptr-1] <= wb_sel[wbptr-1] | sel;
8944
                if (sel[0]) wb_data[wbptr-1][ 7: 0] <= data[ 7: 0];
8945
                if (sel[1]) wb_data[wbptr-1][15: 8] <= data[15: 8];
8946
                if (sel[2]) wb_data[wbptr-1][23:16] <= data[23:16];
8947
                if (sel[3]) wb_data[wbptr-1][31:24] <= data[31:24];
8948
                if (sel[4]) wb_data[wbptr-1][39:32] <= data[39:32];
8949
                if (sel[5]) wb_data[wbptr-1][47:40] <= data[47:40];
8950
                if (sel[6]) wb_data[wbptr-1][55:48] <= data[55:48];
8951
                if (sel[7]) wb_data[wbptr-1][63:56] <= data[63:56];
8952
                wb_id[wbptr-1] <= wb_id[wbptr-1] | (16'd1 << id);
8953
                wb_merges <= wb_merges + 32'd1;
8954
        end
8955
        else begin
8956
                wb_v[wbptr] <= wb_en;
8957
                wb_id[wbptr] <= (16'd1 << id);
8958
                wb_rmw[wbptr] <= rmw;
8959
                wb_ol[wbptr] <= ol;
8960
                wb_sel[wbptr] <= sel;
8961
                wb_addr[wbptr] <= {addr[AMSB:3],3'b0};
8962
                wb_data[wbptr] <= data;
8963
        end
8964
end
8965
endtask
8966 48 robfinch
// Increment the head pointers
8967
// Also increments the instruction counter
8968
// Used when instructions are committed.
8969
// Also clear any outstanding state bits that foul things up.
8970
//
8971
task head_inc;
8972
input [`QBITS] amt;
8973
begin
8974
     head0 <= head0 + amt;
8975
     head1 <= head1 + amt;
8976
     head2 <= head2 + amt;
8977
     head3 <= head3 + amt;
8978
     head4 <= head4 + amt;
8979
     head5 <= head5 + amt;
8980
     head6 <= head6 + amt;
8981
     head7 <= head7 + amt;
8982
     I <= I + amt;
8983 49 robfinch
    if (amt==3'd3) begin
8984
        iqentry_agen[head0] <= `INV;
8985
        iqentry_agen[head1] <= `INV;
8986
        iqentry_agen[head2] <= `INV;
8987
        iqentry_mem[head0] <= `FALSE;
8988
        iqentry_mem[head1] <= `FALSE;
8989
        iqentry_mem[head2] <= `FALSE;
8990
        iqentry_iv[head0] <= `INV;
8991
        iqentry_iv[head1] <= `INV;
8992
        iqentry_iv[head2] <= `INV;
8993
        iqentry_alu[head0] <= `FALSE;
8994
        iqentry_alu[head1] <= `FALSE;
8995
        iqentry_alu[head2] <= `FALSE;
8996
        end
8997
    else if (amt==3'd2) begin
8998 48 robfinch
     iqentry_agen[head0] <= `INV;
8999
     iqentry_agen[head1] <= `INV;
9000 49 robfinch
     iqentry_mem[head0] <= `FALSE;
9001
     iqentry_mem[head1] <= `FALSE;
9002
     iqentry_iv[head0] <= `INV;
9003
     iqentry_iv[head1] <= `INV;
9004
        iqentry_alu[head0] <= `FALSE;
9005
     iqentry_alu[head1] <= `FALSE;
9006 48 robfinch
    end else if (amt==3'd1) begin
9007 49 robfinch
            iqentry_agen[head0] <= `INV;
9008
            iqentry_mem[head0] <= `FALSE;
9009
        iqentry_iv[head0] <= `INV;
9010
        iqentry_alu[head0] <= `FALSE;
9011 48 robfinch
        end
9012
end
9013
endtask
9014
 
9015
task setargs;
9016
input [`QBITS] nn;
9017
input [4:0] id;
9018
input v;
9019
input [63:0] bus;
9020
begin
9021
  if (iqentry_a1_v[nn] == `INV && iqentry_a1_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9022
                iqentry_a1[nn] <= bus;
9023
                iqentry_a1_v[nn] <= `VAL;
9024
  end
9025
  if (iqentry_a2_v[nn] == `INV && iqentry_a2_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9026
                iqentry_a2[nn] <= bus;
9027
                iqentry_a2_v[nn] <= `VAL;
9028
  end
9029
  if (iqentry_a3_v[nn] == `INV && iqentry_a3_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9030
                iqentry_a3[nn] <= bus;
9031
                iqentry_a3_v[nn] <= `VAL;
9032
  end
9033
end
9034
endtask
9035
 
9036
task setinsn;
9037
input [`QBITS] nn;
9038
input [4:0] id;
9039
input v;
9040
input [127:0] bus;
9041
begin
9042
  if (iqentry_iv[nn] == `INV && iqentry_is[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9043
        iqentry_iv   [nn]  <= `VAL;
9044
//      iqentry_Rt   [nn]  <= bus[`IB_RT];
9045
//      iqentry_Rc   [nn]  <= bus[`IB_RC];
9046
//      iqentry_Ra   [nn]  <= bus[`IB_RA];
9047
        iqentry_a0       [nn]  <= bus[`IB_CONST];
9048
        iqentry_imm  [nn]  <= bus[`IB_IMM];
9049
                iqentry_insln[nn]  <= bus[`IB_LN];
9050
                iqentry_bt   [nn]  <= bus[`IB_BT];
9051
                iqentry_alu  [nn]  <= bus[`IB_ALU];
9052
                iqentry_alu0 [nn]  <= bus[`IB_ALU0];
9053
                iqentry_fpu  [nn]  <= bus[`IB_FPU];
9054
                iqentry_fc   [nn]  <= bus[`IB_FC];
9055
                iqentry_canex[nn]  <= bus[`IB_CANEX];
9056 50 robfinch
                iqentry_loadv[nn]  <= bus[`IB_LOADV];
9057 48 robfinch
                iqentry_load [nn]  <= bus[`IB_LOAD];
9058
                iqentry_preload[nn]<= bus[`IB_PRELOAD];
9059 50 robfinch
                iqentry_store[nn]  <= bus[`IB_STORE];
9060
                iqentry_oddball[nn] <= bus[`IB_ODDBALL];
9061
                iqentry_memsz[nn]  <= bus[`IB_MEMSZ];
9062 48 robfinch
                iqentry_mem  [nn]  <= bus[`IB_MEM];
9063
                iqentry_memndx[nn] <= bus[`IB_MEMNDX];
9064
                iqentry_rmw  [nn]  <= bus[`IB_RMW];
9065
                iqentry_memdb[nn]  <= bus[`IB_MEMDB];
9066
                iqentry_memsb[nn]  <= bus[`IB_MEMSB];
9067
                iqentry_shft48[nn] <= bus[`IB_SHFT48];
9068
                iqentry_sei      [nn]    <= bus[`IB_SEI];
9069
                iqentry_aq   [nn]  <= bus[`IB_AQ];
9070
                iqentry_rl   [nn]  <= bus[`IB_RL];
9071
                iqentry_jmp  [nn]  <= bus[`IB_JMP];
9072
                iqentry_br   [nn]  <= bus[`IB_BR];
9073
                iqentry_sync [nn]  <= bus[`IB_SYNC];
9074
                iqentry_fsync[nn]  <= bus[`IB_FSYNC];
9075
        iqentry_rfw  [nn]  <= bus[`IB_RFW];
9076
        iqentry_we   [nn]  <= bus[`IB_WE];
9077
  end
9078
end
9079
endtask
9080
 
9081
// Enqueue fetchbuf0 onto the tail of the instruction queue
9082
task enque0;
9083
input [`QBITS] tail;
9084
input [63:0] seqnum;
9085
input [5:0] venno;
9086
begin
9087
        iqentry_exc[tail] <= `FLT_NONE;
9088
`ifdef SUPPORT_DBG
9089
    if (dbg_imatchA)
9090
        iqentry_exc[tail] <= `FLT_DBG;
9091
    else if (dbg_ctrl[63])
9092
        iqentry_exc[tail] <= `FLT_SSM;
9093
`endif
9094
        iqentry_sn   [tail]    <=  seqnum;
9095
        iqentry_v    [tail]    <=   `VAL;
9096
        iqentry_iv       [tail]    <=   `INV;
9097
        iqentry_is   [tail]    <= tail;
9098
        iqentry_thrd [tail]    <=   fetchbuf0_thrd;
9099
        iqentry_done [tail]    <=    `INV;
9100
        iqentry_cmt  [tail]    <=       `INV;
9101
        iqentry_out  [tail]    <=    `INV;
9102
        iqentry_res  [tail]    <=    `ZERO;
9103
        iqentry_instr[tail]    <=    IsVLS(fetchbuf0_instr) ? (vm[fnM2(fetchbuf0_instr)] ? fetchbuf0_instr : `NOP_INSN) : fetchbuf0_instr;
9104
        iqentry_pt   [tail]    <=  predict_taken0;
9105
        iqentry_agen [tail]    <=    `INV;
9106
        iqentry_state[tail]    <=   IQS_IDLE;
9107
// If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9108
// inherit the previous pc.
9109
//if (IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15] &&
9110
//   (IsBrk(iqentry_instr[idm1(tail)]) && !iqentry_instr[idm1(tail1)][15] && iqentry_v[idm1(tail)]))
9111
//   iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
9112
//else
9113
         iqentry_pc   [tail] <= fetchbuf0_pc;
9114
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf0_instr);
9115
        iqentry_tgt  [tail]    <=       Rt0;
9116
        iqentry_Ra   [tail]    <= Ra0;
9117
        iqentry_Rb   [tail]    <= Rb0;
9118
        iqentry_Rc   [tail]    <= Rc0;
9119
        iqentry_vl   [tail]    <=  vl;
9120
        iqentry_ven  [tail]    <=   venno;
9121
        iqentry_exc  [tail]    <=    `EXC_NONE;
9122
        iqentry_a1   [tail]    <=    rfoa0;
9123
        iqentry_a1_v [tail]    <=    Source1Valid(fetchbuf0_instr) | regIsValid[Ra0s];
9124
        iqentry_a1_s [tail]    <=    rf_source[Ra0s];
9125
        iqentry_a2   [tail]    <=    rfob0;
9126
        iqentry_a2_v [tail]    <=    Source2Valid(fetchbuf0_instr) | regIsValid[Rb0s];
9127
        iqentry_a2_s [tail]    <=    rf_source[Rb0s];
9128
        iqentry_a3   [tail]    <=    rfoc0;
9129
        iqentry_a3_v [tail]    <=    Source3Valid(fetchbuf0_instr) | regIsValid[Rc0s];
9130
        iqentry_a3_s [tail]    <=    rf_source[Rc0s];
9131
end
9132
endtask
9133
 
9134
// Enque fetchbuf1. Fetchbuf1 might be the second instruction to queue so some
9135
// of this code checks to see which tail it is being queued on.
9136
task enque1;
9137
input [`QBITS] tail;
9138
input [63:0] seqnum;
9139
input [5:0] venno;
9140
begin
9141
 iqentry_exc[tail] <= `FLT_NONE;
9142
`ifdef SUPPORT_DBG
9143
    if (dbg_imatchB)
9144
        iqentry_exc[tail] <= `FLT_DBG;
9145
    else if (dbg_ctrl[63])
9146
        iqentry_exc[tail] <= `FLT_SSM;
9147
`endif
9148
        iqentry_sn   [tail]    <=   seqnum;
9149
        iqentry_v    [tail]    <=   `VAL;
9150
        iqentry_iv       [tail]    <=   `INV;
9151
        iqentry_is   [tail]    <= tail;
9152
        iqentry_thrd [tail]    <=   fetchbuf1_thrd;
9153
        iqentry_done [tail]    <=   `INV;
9154
        iqentry_cmt  [tail]    <=       `INV;
9155
        iqentry_out  [tail]    <=   `INV;
9156
        iqentry_res  [tail]    <=   `ZERO;
9157
        iqentry_instr[tail]    <=   IsVLS(fetchbuf1_instr) ? (vm[fnM2(fetchbuf1_instr)] ? fetchbuf1_instr : `NOP_INSN) : fetchbuf1_instr;
9158
        iqentry_pt   [tail]    <=  predict_taken1;
9159
        iqentry_agen [tail]    <=   `INV;
9160
        iqentry_state[tail]    <=   IQS_IDLE;
9161
// If queing 2nd instruction must read from first
9162
if (tail==tail1) begin
9163
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9164
    // inherit the previous pc.
9165
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
9166
//        IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15])
9167
//       iqentry_pc   [tail]    <= fetchbuf0_pc;
9168
//    else
9169
                iqentry_pc   [tail] <= fetchbuf1_pc;
9170
end
9171
else begin
9172
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9173
    // inherit the previous pc.
9174
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
9175
//       (IsBrk(iqentry_instr[idp7(tail)]) && !iqentry_instr[idm1(tail)][15] && iqentry_v[idm1(tail)]))
9176
//       iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
9177
//    else
9178
                iqentry_pc   [tail] <= fetchbuf1_pc;
9179
end
9180
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf1_instr);
9181
        iqentry_tgt  [tail]    <= Rt1;
9182
        iqentry_Ra   [tail]    <= Ra1;
9183
        iqentry_Rb   [tail]    <= Rb1;
9184
        iqentry_Rc   [tail]    <= Rc1;
9185
        iqentry_vl   [tail]    <=  vl;
9186
        iqentry_ven  [tail]    <=   venno;
9187
        iqentry_exc  [tail]    <=   `EXC_NONE;
9188
        iqentry_a1   [tail]    <=       rfoa1;
9189
        iqentry_a1_v [tail]    <=       Source1Valid(fetchbuf1_instr) | regIsValid[Ra1s];
9190
        iqentry_a1_s [tail]    <=       rf_source[Ra1s];
9191
        iqentry_a2   [tail]    <=       rfob1;
9192
        iqentry_a2_v [tail]    <=       Source2Valid(fetchbuf1_instr) | regIsValid[Rb1s];
9193
        iqentry_a2_s [tail]    <=       rf_source[Rb1s];
9194
        iqentry_a3   [tail]    <=       rfoc1;
9195
        iqentry_a3_v [tail]    <=       Source3Valid(fetchbuf1_instr) | regIsValid[Rc1s];
9196
        iqentry_a3_s [tail]    <=       rf_source[Rc1s];
9197
end
9198
endtask
9199
 
9200
// This task takes care of commits for things other than the register file.
9201
task oddball_commit;
9202
input v;
9203
input [`QBITS] head;
9204
reg thread;
9205
begin
9206
    thread = iqentry_thrd[head];
9207
    if (v) begin
9208
        if (|iqentry_exc[head]) begin
9209
            excmiss <= TRUE;
9210
`ifdef SUPPORT_SMT
9211
                excmisspc <= {tvec[3'd0][31:8],ol[thread],5'h00};
9212
            excthrd <= iqentry_thrd[head];
9213
            badaddr[{thread,3'd0}] <= iqentry_a1[head];
9214
            epc0[thread] <= iqentry_pc[head]+ 32'd4;
9215
            epc1[thread] <= epc0[thread];
9216
            epc2[thread] <= epc1[thread];
9217
            epc3[thread] <= epc2[thread];
9218
            epc4[thread] <= epc3[thread];
9219
            epc5[thread] <= epc4[thread];
9220
            epc6[thread] <= epc5[thread];
9221
            epc7[thread] <= epc6[thread];
9222
            epc8[thread] <= epc7[thread];
9223
            im_stack[thread] <= {im_stack[thread][27:0],im};
9224
            ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
9225
            pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
9226
            rs_stack[thread] <= {rs_stack[thread][55:0],rgs[thread]};
9227
            cause[{thread,3'd0}] <= {8'd0,iqentry_exc[head]};
9228
            mstatus[thread][5:3] <= 3'd0;
9229
            mstatus[thread][13:6] <= 8'h00;
9230
            mstatus[thread][19:14] <= 6'd0;
9231
`else
9232
                excmisspc <= {tvec[3'd0][31:8],ol,5'h00};
9233
            excthrd <= iqentry_thrd[head];
9234
            badaddr[{thread,3'd0}] <= iqentry_a1[head];
9235
            epc0 <= iqentry_pc[head]+ 32'd4;
9236
            epc1 <= epc0;
9237
            epc2 <= epc1;
9238
            epc3 <= epc2;
9239
            epc4 <= epc3;
9240
            epc5 <= epc4;
9241
            epc6 <= epc5;
9242
            epc7 <= epc6;
9243
            epc8 <= epc7;
9244
            im_stack <= {im_stack[27:0],im};
9245
            ol_stack <= {ol_stack[13:0],ol};
9246
            pl_stack <= {pl_stack[55:0],cpl};
9247
            rs_stack <= {rs_stack[55:0],rgs};
9248
            cause[{thread,3'd0}] <= {8'd0,iqentry_exc[head]};
9249
            mstatus[5:3] <= 3'd0;
9250
            mstatus[13:6] <= 8'h00;
9251
            mstatus[19:14] <= 6'd0;
9252
`endif
9253 49 robfinch
                                                wb_en <= `TRUE;
9254 48 robfinch
            sema[0] <= 1'b0;
9255
            ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
9256
`ifdef SUPPORT_DBG
9257
            dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
9258
            dbg_ctrl[63] <= FALSE;
9259
`endif
9260
        end
9261
        else
9262
        case(iqentry_instr[head][`INSTRUCTION_OP])
9263
        `BRK:
9264
                        // BRK is treated as a nop unless it's a software interrupt or a
9265
                        // hardware interrupt at a higher priority than the current priority.
9266
                if ((iqentry_instr[head][23:19] > 5'd0) || iqentry_instr[head][18:16] > im) begin
9267
                            excmiss <= TRUE;
9268
`ifdef SUPPORT_SMT
9269
                        excmisspc <= {tvec[3'd0][31:8],ol[thread],5'h00};
9270
                        excthrd <= iqentry_thrd[head];
9271
                    epc0[thread] <= iqentry_pc[head] + {iqentry_instr[head][23:19],2'b00};
9272
                    epc1[thread] <= epc0[thread];
9273
                    epc2[thread] <= epc1[thread];
9274
                    epc3[thread] <= epc2[thread];
9275
                    epc4[thread] <= epc3[thread];
9276
                    epc5[thread] <= epc4[thread];
9277
                    epc6[thread] <= epc5[thread];
9278
                    epc7[thread] <= epc6[thread];
9279
                    epc8[thread] <= epc7[thread];
9280
                    im_stack[thread] <= {im_stack[thread][27:0],im};
9281
                    ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
9282
                    pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
9283
                    rs_stack[thread] <= {rs_stack[thread][55:0],rgs[thread]};
9284
                    mstatus[thread][19:14] <= 6'd0;
9285
                    cause[{thread,3'd0}] <= {iqentry_instr[head][31:24],iqentry_instr[head][13:6]};
9286
                    mstatus[thread][5:3] <= 3'd0;
9287
                        mstatus[thread][13:6] <= 8'h00;
9288
                    // For hardware interrupts only, set a new mask level
9289
                    // Select register set according to interrupt level
9290
                    if (iqentry_instr[head][23:19]==5'd0) begin
9291
                        mstatus[thread][2:0] <= 3'd7;//iqentry_instr[head][18:16];
9292
                        mstatus[thread][42:40] <= iqentry_instr[head][18:16];
9293
                        mstatus[thread][19:14] <= {3'b0,iqentry_instr[head][18:16]};
9294
                    end
9295
                    else
9296
                        mstatus[thread][19:14] <= 6'd0;
9297
`else
9298
                        excmisspc <= {tvec[3'd0][31:8],ol,5'h00};
9299
                        excthrd <= iqentry_thrd[head];
9300
                    epc0 <= iqentry_pc[head] + {iqentry_instr[head][23:19],2'b00};
9301
                    epc1 <= epc0;
9302
                    epc2 <= epc1;
9303
                    epc3 <= epc2;
9304
                    epc4 <= epc3;
9305
                    epc5 <= epc4;
9306
                    epc6 <= epc5;
9307
                    epc7 <= epc6;
9308
                    epc8 <= epc7;
9309
                    im_stack <= {im_stack[27:0],im};
9310
                    ol_stack <= {ol_stack[13:0],ol};
9311
                    pl_stack <= {pl_stack[55:0],cpl};
9312
                    rs_stack <= {rs_stack[55:0],rgs};
9313
                    mstatus[19:14] <= 6'd0;
9314
                    cause[{thread,3'd0}] <= {iqentry_instr[head][31:24],iqentry_instr[head][13:6]};
9315
                    mstatus[5:3] <= 3'd0;
9316
                        mstatus[13:6] <= 8'h00;
9317
                    // For hardware interrupts only, set a new mask level
9318
                    // Select register set according to interrupt level
9319
                    if (iqentry_instr[head][23:19]==5'd0) begin
9320
                        mstatus[2:0] <= 3'd7;//iqentry_instr[head][18:16];
9321
                        mstatus[42:40] <= iqentry_instr[head][18:16];
9322
                        mstatus[19:14] <= {3'b0,iqentry_instr[head][18:16]};
9323
                    end
9324
                    else
9325
                        mstatus[19:14] <= 6'd0;
9326
`endif
9327
                    sema[0] <= 1'b0;
9328
                    ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
9329
`ifdef SUPPORT_DBG
9330
                    dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
9331
                    dbg_ctrl[63] <= FALSE;
9332
`endif
9333
                end
9334
        `IVECTOR:
9335
            casez(iqentry_tgt[head])
9336
            8'b00100xxx:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
9337
            8'b00101111:  vl <= iqentry_res[head];
9338
            default:    ;
9339
            endcase
9340
        `R2:
9341
            case(iqentry_instr[head][`INSTRUCTION_S2])
9342
            `R1:        case(iqentry_instr[head][20:16])
9343
                        `CHAIN_OFF:     cr0[18] <= 1'b0;
9344
                        `CHAIN_ON:      cr0[18] <= 1'b1;
9345
                        //`SETWB:               wbrcd[pcr[5:0]] <= 1'b1;
9346
                        default:        ;
9347
                                endcase
9348
            `VMOV:  casez(iqentry_tgt[head])
9349
                    12'b1111111_00???:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
9350
                    12'b1111111_01111:  vl <= iqentry_res[head];
9351
                    default:    ;
9352
                    endcase
9353
`ifdef SUPPORT_SMT
9354
            `SEI:   mstatus[thread][2:0] <= iqentry_res[head][2:0];   // S1
9355
`else
9356
            `SEI:   mstatus[2:0] <= iqentry_res[head][2:0];   // S1
9357
`endif
9358
            `RTI:   begin
9359
                            excmiss <= TRUE;
9360
`ifdef SUPPORT_SMT
9361
                        excmisspc <= epc0[thread];
9362
                        excthrd <= thread;
9363
                        mstatus[thread][3:0] <= im_stack[thread][3:0];
9364
                        mstatus[thread][5:4] <= ol_stack[thread][1:0];
9365
                        mstatus[thread][13:6] <= pl_stack[thread][7:0];
9366
                        mstatus[thread][19:14] <= rs_stack[thread][5:0];
9367
                        im_stack[thread] <= {4'd15,im_stack[thread][27:4]};
9368
                        ol_stack[thread] <= {2'd0,ol_stack[thread][15:2]};
9369
                        pl_stack[thread] <= {8'h00,pl_stack[thread][63:8]};
9370
                        rs_stack[thread] <= {8'h00,rs_stack[thread][63:8]};
9371
                    epc0[thread] <= epc1[thread];
9372
                    epc1[thread] <= epc2[thread];
9373
                    epc2[thread] <= epc3[thread];
9374
                    epc3[thread] <= epc4[thread];
9375
                    epc4[thread] <= epc5[thread];
9376
                    epc5[thread] <= epc6[thread];
9377
                    epc6[thread] <= epc7[thread];
9378
                    epc7[thread] <= epc8[thread];
9379
                    epc8[thread] <= {tvec[0][31:8], ol[thread], 5'h0};
9380
`else
9381
                        excmisspc <= epc0;
9382
                        excthrd <= thread;
9383
                        mstatus[3:0] <= im_stack[3:0];
9384
                        mstatus[5:4] <= ol_stack[1:0];
9385
                        mstatus[13:6] <= pl_stack[7:0];
9386
                        mstatus[19:14] <= rs_stack[5:0];
9387
                        im_stack <= {4'd15,im_stack[31:4]};
9388
                        ol_stack <= {2'd0,ol_stack[15:2]};
9389
                        pl_stack <= {8'h00,pl_stack[63:8]};
9390
                        rs_stack <= {8'h00,rs_stack[63:8]};
9391
                    epc0 <= epc1;
9392
                    epc1 <= epc2;
9393
                    epc2 <= epc3;
9394
                    epc3 <= epc4;
9395
                    epc4 <= epc5;
9396
                    epc5 <= epc6;
9397
                    epc6 <= epc7;
9398
                    epc7 <= epc8;
9399
                    epc8 <= {tvec[0][31:8], ol, 5'h0};
9400
`endif
9401
                    sema[0] <= 1'b0;
9402
                    sema[iqentry_res[head][5:0]] <= 1'b0;
9403
                    vqe0  <= ve_hold[ 5: 0];
9404
                    vqet0 <= ve_hold[21:16];
9405
                    vqe1  <= ve_hold[37:32];
9406
                    vqet1 <= ve_hold[53:48];
9407
`ifdef SUPPORT_DBG
9408
                    dbg_ctrl[62:55] <= {FALSE,dbg_ctrl[62:56]};
9409
                    dbg_ctrl[63] <= dbg_ctrl[55];
9410
`endif
9411
                    end
9412 49 robfinch
            default: ;
9413
            endcase
9414
        `MEMNDX:
9415
            case(iqentry_instr[head][`INSTRUCTION_S2])
9416 48 robfinch
            `CACHEX:
9417 49 robfinch
                    case(iqentry_instr[head][22:18])
9418 48 robfinch
                    5'h03:  invic <= TRUE;
9419
                    5'h10:  cr0[30] <= FALSE;
9420
                    5'h11:  cr0[30] <= TRUE;
9421
                    default:    ;
9422
                    endcase
9423
            default: ;
9424
            endcase
9425
        `CSRRW:
9426
                        begin
9427
                        write_csr(iqentry_instr[head][31:16],iqentry_a1[head],thread);
9428
                        end
9429
        `REX:
9430
`ifdef SUPPORT_SMT
9431
            // Can only redirect to a lower level
9432
            if (ol[thread] < iqentry_instr[head][13:11]) begin
9433
                mstatus[thread][5:3] <= iqentry_instr[head][13:11];
9434
                badaddr[{thread,iqentry_instr[head][13:11]}] <= badaddr[{thread,ol[thread]}];
9435
                cause[{thread,iqentry_instr[head][13:11]}] <= cause[{thread,ol[thread]}];
9436
                mstatus[thread][13:6] <= iqentry_instr[head][23:16] | iqentry_a1[head][7:0];
9437
            end
9438
`else
9439
            if (ol < iqentry_instr[head][13:11]) begin
9440
                mstatus[5:3] <= iqentry_instr[head][13:11];
9441
                badaddr[{thread,iqentry_instr[head][13:11]}] <= badaddr[{thread,ol}];
9442
                cause[{thread,iqentry_instr[head][13:11]}] <= cause[{thread,ol}];
9443
                mstatus[13:6] <= iqentry_instr[head][23:16] | iqentry_a1[head][7:0];
9444
            end
9445
`endif
9446
        `CACHE:
9447 49 robfinch
            case(iqentry_instr[head][17:13])
9448 48 robfinch
            5'h03:  invic <= TRUE;
9449
            5'h10:  cr0[30] <= FALSE;
9450
            5'h11:  cr0[30] <= TRUE;
9451
            default:    ;
9452
            endcase
9453
        `FLOAT:
9454
            case(iqentry_instr[head][`INSTRUCTION_S2])
9455 49 robfinch
            `FRM: begin
9456
                                fp1_rm <= iqentry_res[head][2:0];
9457
                                fp2_rm <= iqentry_res[head][2:0];
9458
                                end
9459 48 robfinch
            `FCX:
9460
                begin
9461 49 robfinch
                    fp1_sx <= fp1_sx & ~iqentry_res[head][5];
9462
                    fp1_inex <= fp1_inex & ~iqentry_res[head][4];
9463
                    fp1_dbzx <= fp1_dbzx & ~(iqentry_res[head][3]|iqentry_res[head][0]);
9464
                    fp1_underx <= fp1_underx & ~iqentry_res[head][2];
9465
                    fp1_overx <= fp1_overx & ~iqentry_res[head][1];
9466
                    fp1_giopx <= fp1_giopx & ~iqentry_res[head][0];
9467
                    fp1_infdivx <= fp1_infdivx & ~iqentry_res[head][0];
9468
                    fp1_zerozerox <= fp1_zerozerox & ~iqentry_res[head][0];
9469
                    fp1_subinfx   <= fp1_subinfx   & ~iqentry_res[head][0];
9470
                    fp1_infzerox  <= fp1_infzerox  & ~iqentry_res[head][0];
9471
                    fp1_NaNCmpx   <= fp1_NaNCmpx   & ~iqentry_res[head][0];
9472
                    fp1_swtx <= 1'b0;
9473 48 robfinch
                end
9474
            `FDX:
9475
                begin
9476 49 robfinch
                    fp1_inexe <= fp1_inexe     & ~iqentry_res[head][4];
9477
                    fp1_dbzxe <= fp1_dbzxe     & ~iqentry_res[head][3];
9478
                    fp1_underxe <= fp1_underxe & ~iqentry_res[head][2];
9479
                    fp1_overxe <= fp1_overxe   & ~iqentry_res[head][1];
9480
                    fp1_invopxe <= fp1_invopxe & ~iqentry_res[head][0];
9481 48 robfinch
                end
9482
            `FEX:
9483
                begin
9484 49 robfinch
                    fp1_inexe <= fp1_inexe     | iqentry_res[head][4];
9485
                    fp1_dbzxe <= fp1_dbzxe     | iqentry_res[head][3];
9486
                    fp1_underxe <= fp1_underxe | iqentry_res[head][2];
9487
                    fp1_overxe <= fp1_overxe   | iqentry_res[head][1];
9488
                    fp1_invopxe <= fp1_invopxe | iqentry_res[head][0];
9489 48 robfinch
                end
9490
            default:
9491
                begin
9492
                    // 31 to 29 is rounding mode
9493
                    // 28 to 24 are exception enables
9494
                    // 23 is nsfp
9495
                    // 22 is a fractie
9496 49 robfinch
                    fp1_fractie <= iqentry_a0[head][22];
9497
                    fp1_raz <= iqentry_a0[head][21];
9498 48 robfinch
                    // 20 is a 0
9499 49 robfinch
                    fp1_neg <= iqentry_a0[head][19];
9500
                    fp1_pos <= iqentry_a0[head][18];
9501
                    fp1_zero <= iqentry_a0[head][17];
9502
                    fp1_inf <= iqentry_a0[head][16];
9503 48 robfinch
                    // 15 swtx
9504
                    // 14 
9505 49 robfinch
                    fp1_inex <= fp1_inex | (fp1_inexe & iqentry_a0[head][14]);
9506
                    fp1_dbzx <= fp1_dbzx | (fp1_dbzxe & iqentry_a0[head][13]);
9507
                    fp1_underx <= fp1_underx | (fp1_underxe & iqentry_a0[head][12]);
9508
                    fp1_overx <= fp1_overx | (fp1_overxe & iqentry_a0[head][11]);
9509 48 robfinch
                    //fp_giopx <= fp_giopx | (fp_giopxe & iqentry_res2[head][10]);
9510
                    //fp_invopx <= fp_invopx | (fp_invopxe & iqentry_res2[head][24]);
9511
                    //
9512 49 robfinch
                    fp1_cvtx <= fp1_cvtx |  (fp1_giopxe & iqentry_a0[head][7]);
9513
                    fp1_sqrtx <= fp1_sqrtx |  (fp1_giopxe & iqentry_a0[head][6]);
9514
                    fp1_NaNCmpx <= fp1_NaNCmpx |  (fp1_giopxe & iqentry_a0[head][5]);
9515
                    fp1_infzerox <= fp1_infzerox |  (fp1_giopxe & iqentry_a0[head][4]);
9516
                    fp1_zerozerox <= fp1_zerozerox |  (fp1_giopxe & iqentry_a0[head][3]);
9517
                    fp1_infdivx <= fp1_infdivx | (fp1_giopxe & iqentry_a0[head][2]);
9518
                    fp1_subinfx <= fp1_subinfx | (fp1_giopxe & iqentry_a0[head][1]);
9519
                    fp1_snanx <= fp1_snanx | (fp1_giopxe & iqentry_a0[head][0]);
9520 48 robfinch
 
9521
                end
9522
            endcase
9523
        default:    ;
9524
        endcase
9525
        // Once the flow control instruction commits, NOP it out to allow
9526
        // pending stores to be issued.
9527
        iqentry_instr[head][5:0] <= `NOP;
9528
    end
9529
end
9530
endtask
9531
 
9532
// CSR access tasks
9533
task read_csr;
9534
input [13:0] csrno;
9535
output [63:0] dat;
9536
input thread;
9537
begin
9538
`ifdef SUPPORT_SMT
9539
    if (csrno[11:10] >= ol[thread])
9540
`else
9541
    if (csrno[11:10] >= ol)
9542
`endif
9543
    casez(csrno[9:0])
9544
    `CSR_CR0:       dat <= cr0;
9545
    `CSR_HARTID:    dat <= hartid;
9546
    `CSR_TICK:      dat <= tick;
9547
    `CSR_PCR:       dat <= pcr;
9548
    `CSR_PCR2:      dat <= pcr2;
9549 49 robfinch
    `CSR_PMR:                           dat <= pmr;
9550 48 robfinch
    `CSR_WBRCD:         dat <= wbrcd;
9551
    `CSR_SEMA:      dat <= sema;
9552
    `CSR_SBL:       dat <= sbl;
9553
    `CSR_SBU:       dat <= sbu;
9554
    `CSR_TCB:           dat <= tcb;
9555 49 robfinch
    `CSR_FSTAT:     dat <= {fp1_rgs,fp1_status};
9556 48 robfinch
`ifdef SUPPORT_DBG
9557
    `CSR_DBAD0:     dat <= dbg_adr0;
9558
    `CSR_DBAD1:     dat <= dbg_adr1;
9559
    `CSR_DBAD2:     dat <= dbg_adr2;
9560
    `CSR_DBAD3:     dat <= dbg_adr3;
9561
    `CSR_DBCTRL:    dat <= dbg_ctrl;
9562
    `CSR_DBSTAT:    dat <= dbg_stat;
9563
`endif
9564
    `CSR_CAS:       dat <= cas;
9565
    `CSR_TVEC:      dat <= tvec[csrno[2:0]];
9566
    `CSR_BADADR:    dat <= badaddr[{thread,csrno[13:11]}];
9567
    `CSR_CAUSE:     dat <= {48'd0,cause[{thread,csrno[13:11]}]};
9568
`ifdef SUPPORT_SMT
9569
    `CSR_IM_STACK:      dat <= im_stack[thread];
9570
    `CSR_OL_STACK:      dat <= ol_stack[thread];
9571
    `CSR_PL_STACK:      dat <= pl_stack[thread];
9572
    `CSR_RS_STACK:      dat <= rs_stack[thread];
9573
    `CSR_STATUS:    dat <= mstatus[thread][63:0];
9574
    `CSR_EPC0:      dat <= epc0[thread];
9575
    `CSR_EPC1:      dat <= epc1[thread];
9576
    `CSR_EPC2:      dat <= epc2[thread];
9577
    `CSR_EPC3:      dat <= epc3[thread];
9578
    `CSR_EPC4:      dat <= epc4[thread];
9579
    `CSR_EPC5:      dat <= epc5[thread];
9580
    `CSR_EPC6:      dat <= epc6[thread];
9581
    `CSR_EPC7:      dat <= epc7[thread];
9582
`else
9583
    `CSR_IM_STACK:      dat <= im_stack;
9584
    `CSR_OL_STACK:      dat <= ol_stack;
9585
    `CSR_PL_STACK:      dat <= pl_stack;
9586
    `CSR_RS_STACK:      dat <= rs_stack;
9587
    `CSR_STATUS:    dat <= mstatus[63:0];
9588
    `CSR_EPC0:      dat <= epc0;
9589
    `CSR_EPC1:      dat <= epc1;
9590
    `CSR_EPC2:      dat <= epc2;
9591
    `CSR_EPC3:      dat <= epc3;
9592
    `CSR_EPC4:      dat <= epc4;
9593
    `CSR_EPC5:      dat <= epc5;
9594
    `CSR_EPC6:      dat <= epc6;
9595
    `CSR_EPC7:      dat <= epc7;
9596
`endif
9597
    `CSR_CODEBUF:   dat <= codebuf[csrno[5:0]];
9598
    `CSR_TIME:          dat <= wc_times;
9599
    `CSR_INFO:
9600
                    case(csrno[3:0])
9601
                    4'd0:   dat <= "Finitron";  // manufacturer
9602
                    4'd1:   dat <= "        ";
9603
                    4'd2:   dat <= "64 bit  ";  // CPU class
9604
                    4'd3:   dat <= "        ";
9605
                    4'd4:   dat <= "FT64    ";  // Name
9606
                    4'd5:   dat <= "        ";
9607
                    4'd6:   dat <= 64'd1;       // model #
9608
                    4'd7:   dat <= 64'd1;       // serial number
9609
                    4'd8:   dat <= {32'd16384,32'd16384};   // cache sizes instruction,data
9610
                    4'd9:   dat <= 64'd0;
9611
                    default:    dat <= 64'd0;
9612
                    endcase
9613
    default:    begin
9614
                        $display("Unsupported CSR:%h",csrno[10:0]);
9615
                        dat <= 64'hEEEEEEEEEEEEEEEE;
9616
                        end
9617
    endcase
9618
    else
9619
        dat <= 64'h0;
9620
end
9621
endtask
9622
 
9623
task write_csr;
9624
input [13:0] csrno;
9625
input [63:0] dat;
9626
input thread;
9627
begin
9628
`ifdef SUPPORT_SMT
9629
    if (csrno[11:10] >= ol[thread])
9630
`else
9631
    if (csrno[11:10] >= ol)
9632
`endif
9633
    case(csrno[13:12])
9634
    2'd1:   // CSRRW
9635
        casez(csrno[9:0])
9636
        `CSR_CR0:       cr0 <= dat;
9637
        `CSR_PCR:       pcr <= dat[31:0];
9638
        `CSR_PCR2:      pcr2 <= dat;
9639 49 robfinch
        `CSR_PMR:       case(`NUM_IDU)
9640
                                                0,1:     pmr[0] <= 1'b1;
9641
                                                2:
9642
                                                        begin
9643
                                                                        if (dat[1:0]==2'b00)
9644
                                                                                pmr[1:0] <= 2'b01;
9645
                                                                        else
9646
                                                                                pmr[1:0] <= dat[1:0];
9647
                                                                        pmr[63:2] <= dat[63:2];
9648
                                                                end
9649
                                                3:
9650
                                                        begin
9651
                                                                        if (dat[2:0]==3'b000)
9652
                                                                                pmr[2:0] <= 3'b001;
9653
                                                                        else
9654
                                                                                pmr[2:0] <= dat[2:0];
9655
                                                                        pmr[63:3] <= dat[63:3];
9656
                                                                end
9657
                                                default:        pmr[0] <= 1'b1;
9658
                                                endcase
9659 48 robfinch
        `CSR_WBRCD:             wbrcd <= dat;
9660
        `CSR_SEMA:      sema <= dat;
9661
        `CSR_SBL:       sbl <= dat[31:0];
9662
        `CSR_SBU:       sbu <= dat[31:0];
9663
        `CSR_TCB:               tcb <= dat;
9664 49 robfinch
        `CSR_FSTAT:             fpu1_csr[37:32] <= dat[37:32];
9665 48 robfinch
        `CSR_BADADR:    badaddr[{thread,csrno[13:11]}] <= dat;
9666
        `CSR_CAUSE:     cause[{thread,csrno[13:11]}] <= dat[15:0];
9667
`ifdef SUPPORT_DBG
9668
        `CSR_DBAD0:     dbg_adr0 <= dat[AMSB:0];
9669
        `CSR_DBAD1:     dbg_adr1 <= dat[AMSB:0];
9670
        `CSR_DBAD2:     dbg_adr2 <= dat[AMSB:0];
9671
        `CSR_DBAD3:     dbg_adr3 <= dat[AMSB:0];
9672
        `CSR_DBCTRL:    dbg_ctrl <= dat;
9673
`endif
9674
        `CSR_CAS:       cas <= dat;
9675
        `CSR_TVEC:      tvec[csrno[2:0]] <= dat[31:0];
9676
`ifdef SUPPORT_SMT
9677
        `CSR_IM_STACK:  im_stack[thread] <= dat[31:0];
9678
        `CSR_OL_STACK:  ol_stack[thread] <= dat[15:0];
9679
        `CSR_PL_STACK:  pl_stack[thread] <= dat;
9680
        `CSR_RS_STACK:  rs_stack[thread] <= dat;
9681
        `CSR_STATUS:    mstatus[thread][63:0] <= dat;
9682
        `CSR_EPC0:      epc0[thread] <= dat;
9683
        `CSR_EPC1:      epc1[thread] <= dat;
9684
        `CSR_EPC2:      epc2[thread] <= dat;
9685
        `CSR_EPC3:      epc3[thread] <= dat;
9686
        `CSR_EPC4:      epc4[thread] <= dat;
9687
        `CSR_EPC5:      epc5[thread] <= dat;
9688
        `CSR_EPC6:      epc6[thread] <= dat;
9689
        `CSR_EPC7:      epc7[thread] <= dat;
9690
`else
9691
        `CSR_IM_STACK:  im_stack <= dat[31:0];
9692
        `CSR_OL_STACK:  ol_stack <= dat[15:0];
9693
        `CSR_PL_STACK:  pl_stack <= dat;
9694
        `CSR_RS_STACK:  rs_stack <= dat;
9695
        `CSR_STATUS:    mstatus[63:0] <= dat;
9696
        `CSR_EPC0:      epc0 <= dat;
9697
        `CSR_EPC1:      epc1 <= dat;
9698
        `CSR_EPC2:      epc2 <= dat;
9699
        `CSR_EPC3:      epc3 <= dat;
9700
        `CSR_EPC4:      epc4 <= dat;
9701
        `CSR_EPC5:      epc5 <= dat;
9702
        `CSR_EPC6:      epc6 <= dat;
9703
        `CSR_EPC7:      epc7 <= dat;
9704
`endif
9705
                `CSR_TIME:              begin
9706
                                                ld_time <= 6'h3f;
9707
                                                wc_time_dat <= dat;
9708
                                                end
9709
        `CSR_CODEBUF:   codebuf[csrno[5:0]] <= dat;
9710
        default:    ;
9711
        endcase
9712
    2'd2:   // CSRRS
9713
        case(csrno[9:0])
9714
        `CSR_CR0:       cr0 <= cr0 | dat;
9715
        `CSR_PCR:       pcr[31:0] <= pcr[31:0] | dat[31:0];
9716
        `CSR_PCR2:      pcr2 <= pcr2 | dat;
9717 49 robfinch
        `CSR_PMR:                               pmr <= pmr | dat;
9718 48 robfinch
        `CSR_WBRCD:             wbrcd <= wbrcd | dat;
9719
`ifdef SUPPORT_DBG
9720
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl | dat;
9721
`endif
9722
        `CSR_SEMA:      sema <= sema | dat;
9723
`ifdef SUPPORT_SMT
9724
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] | dat;
9725
`else
9726
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] | dat;
9727
`endif
9728
        default:    ;
9729
        endcase
9730
    2'd3:   // CSRRC
9731
        case(csrno[9:0])
9732
        `CSR_CR0:       cr0 <= cr0 & ~dat;
9733
        `CSR_PCR:       pcr <= pcr & ~dat;
9734
        `CSR_PCR2:      pcr2 <= pcr2 & ~dat;
9735 49 robfinch
        `CSR_PMR:                       begin
9736
                                                                if (dat[1:0]==2'b11)
9737
                                                                        pmr[1:0] <= 2'b01;
9738
                                                                else
9739
                                                                        pmr[1:0] <= pmr[1:0] & ~dat[1:0];
9740
                                                                pmr[63:2] <= pmr[63:2] & ~dat[63:2];
9741
                                                                end
9742 48 robfinch
        `CSR_WBRCD:             wbrcd <= wbrcd & ~dat;
9743
`ifdef SUPPORT_DBG
9744
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl & ~dat;
9745
`endif
9746
        `CSR_SEMA:      sema <= sema & ~dat;
9747
`ifdef SUPPORT_SMT
9748
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] & ~dat;
9749
`else
9750
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] & ~dat;
9751
`endif
9752
        default:    ;
9753
        endcase
9754
    default:    ;
9755
    endcase
9756
end
9757
endtask
9758
 
9759
/*
9760
task aluissue;
9761
input alu_idle;
9762
input [QENTRIES-1:0] iq_alu0;
9763
input [1:0] slot;
9764
begin
9765
        if (alu_idle) begin
9766
                if (could_issue[head0] && iqentry_alu[head0]
9767
                && !iq_alu0[head0]      // alu0only
9768
                && !iqentry_issue[head0]) begin
9769
                  iqentry_issue[head0] = `TRUE;
9770
                  iqentry_islot[head0] = slot;
9771
                end
9772
                else if (could_issue[head1] && !iqentry_issue[head1] && iqentry_alu[head1]
9773
                && !iq_alu0[head1])
9774
                begin
9775
                  iqentry_issue[head1] = `TRUE;
9776
                  iqentry_islot[head1] = slot;
9777
                end
9778
                else if (could_issue[head2] && !iqentry_issue[head2] && iqentry_alu[head2]
9779
                && !iq_alu0[head2]
9780
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
9781
                )
9782
                begin
9783
                        iqentry_issue[head2] = `TRUE;
9784
                        iqentry_islot[head2] = slot;
9785
                end
9786
                else if (could_issue[head3] && !iqentry_issue[head3] && iqentry_alu[head3]
9787
                && !iq_alu0[head3]
9788
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
9789
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
9790
                                ((!iqentry_v[head0])
9791
                        &&   (!iqentry_v[head1]))
9792
                        )
9793
                ) begin
9794
                        iqentry_issue[head3] = `TRUE;
9795
                        iqentry_islot[head3] = slot;
9796
                end
9797
                else if (could_issue[head4] && !iqentry_issue[head4] && iqentry_alu[head4]
9798
                && !iq_alu0[head4]
9799
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
9800
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
9801
                                ((!iqentry_v[head0])
9802
                        &&   (!iqentry_v[head1]))
9803
                        )
9804
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
9805
                                ((!iqentry_v[head0])
9806
                        &&   (!iqentry_v[head1])
9807
                        &&   (!iqentry_v[head2]))
9808
                        )
9809
                ) begin
9810
                        iqentry_issue[head4] = `TRUE;
9811
                        iqentry_islot[head4] = slot;
9812
                end
9813
                else if (could_issue[head5] && !iqentry_issue[head5] && iqentry_alu[head5]
9814
                && !iq_alu0[head5]
9815
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
9816
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
9817
                                ((!iqentry_v[head0])
9818
                        &&   (!iqentry_v[head1]))
9819
                        )
9820
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
9821
                                ((!iqentry_v[head0])
9822
                        &&   (!iqentry_v[head1])
9823
                        &&   (!iqentry_v[head2]))
9824
                        )
9825
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
9826
                                ((!iqentry_v[head0])
9827
                        &&   (!iqentry_v[head1])
9828
                        &&   (!iqentry_v[head2])
9829
                        &&   (!iqentry_v[head3]))
9830
                        )
9831
                ) begin
9832
                        iqentry_issue[head5] = `TRUE;
9833
                        iqentry_islot[head5] = slot;
9834
                end
9835
                else if (could_issue[head6] && !iqentry_issue[head6] && iqentry_alu[head6]
9836
                && !iq_alu0[head6]
9837
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
9838
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
9839
                                ((!iqentry_v[head0])
9840
                        &&   (!iqentry_v[head1]))
9841
                        )
9842
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
9843
                                ((!iqentry_v[head0])
9844
                        &&   (!iqentry_v[head1])
9845
                        &&   (!iqentry_v[head2]))
9846
                        )
9847
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
9848
                                ((!iqentry_v[head0])
9849
                        &&   (!iqentry_v[head1])
9850
                        &&   (!iqentry_v[head2])
9851
                        &&   (!iqentry_v[head3]))
9852
                        )
9853
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
9854
                                ((!iqentry_v[head0])
9855
                        &&   (!iqentry_v[head1])
9856
                        &&   (!iqentry_v[head2])
9857
                        &&   (!iqentry_v[head3])
9858
                        &&   (!iqentry_v[head4]))
9859
                        )
9860
                ) begin
9861
                        iqentry_issue[head6] = `TRUE;
9862
                        iqentry_islot[head6] = slot;
9863
                end
9864
                else if (could_issue[head7] && !iqentry_issue[head7] && iqentry_alu[head7]
9865
                && !iq_alu0[head7]
9866
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
9867
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
9868
                                ((!iqentry_v[head0])
9869
                        &&   (!iqentry_v[head1]))
9870
                        )
9871
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
9872
                                ((!iqentry_v[head0])
9873
                        &&   (!iqentry_v[head1])
9874
                        &&   (!iqentry_v[head2]))
9875
                        )
9876
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
9877
                                ((!iqentry_v[head0])
9878
                        &&   (!iqentry_v[head1])
9879
                        &&   (!iqentry_v[head2])
9880
                        &&   (!iqentry_v[head3]))
9881
                        )
9882
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
9883
                                ((!iqentry_v[head0])
9884
                        &&   (!iqentry_v[head1])
9885
                        &&   (!iqentry_v[head2])
9886
                        &&   (!iqentry_v[head3])
9887
                        &&   (!iqentry_v[head4]))
9888
                        )
9889
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
9890
                                ((!iqentry_v[head0])
9891
                        &&   (!iqentry_v[head1])
9892
                        &&   (!iqentry_v[head2])
9893
                        &&   (!iqentry_v[head3])
9894
                        &&   (!iqentry_v[head4])
9895
                        &&   (!iqentry_v[head5]))
9896
                        )
9897
                ) begin
9898
                        iqentry_issue[head7] = `TRUE;
9899
                        iqentry_islot[head7] = slot;
9900
                end
9901
        end
9902
end
9903
endtask
9904
 
9905
task fpuissue;
9906
input fp_idle;
9907
input [1:0] slot;
9908
begin
9909
        if (fp_idle) begin
9910
    if (could_issue[head0] && iqentry_fpu[head0]) begin
9911
      iqentry_fpu_issue[head0] = `TRUE;
9912
      iqentry_fpu_islot[head0] = slot;
9913
    end
9914
    else if (could_issue[head1] && iqentry_fpu[head1])
9915
    begin
9916
      iqentry_fpu_issue[head1] = `TRUE;
9917
      iqentry_fpu_islot[head1] = slot;
9918
    end
9919
    else if (could_issue[head2] && iqentry_fpu[head2]
9920
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
9921
    ) begin
9922
      iqentry_fpu_issue[head2] = `TRUE;
9923
      iqentry_fpu_islot[head2] = slot;
9924
    end
9925
    else if (could_issue[head3] && iqentry_fpu[head3]
9926
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
9927
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
9928
                ((!iqentry_v[head0])
9929
        &&   (!iqentry_v[head1]))
9930
        )
9931
    ) begin
9932
      iqentry_fpu_issue[head3] = `TRUE;
9933
      iqentry_fpu_islot[head3] = slot;
9934
    end
9935
    else if (could_issue[head4] && iqentry_fpu[head4]
9936
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
9937
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
9938
                ((!iqentry_v[head0])
9939
        &&   (!iqentry_v[head1]))
9940
        )
9941
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
9942
                ((!iqentry_v[head0])
9943
        &&   (!iqentry_v[head1])
9944
        &&   (!iqentry_v[head2]))
9945
        )
9946
    ) begin
9947
      iqentry_fpu_issue[head4] = `TRUE;
9948
      iqentry_fpu_islot[head4] = slot;
9949
    end
9950
    else if (could_issue[head5] && iqentry_fpu[head5]
9951
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
9952
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
9953
                ((!iqentry_v[head0])
9954
        &&   (!iqentry_v[head1]))
9955
        )
9956
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
9957
                ((!iqentry_v[head0])
9958
        &&   (!iqentry_v[head1])
9959
        &&   (!iqentry_v[head2]))
9960
        )
9961
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
9962
                ((!iqentry_v[head0])
9963
        &&   (!iqentry_v[head1])
9964
        &&   (!iqentry_v[head2])
9965
        &&   (!iqentry_v[head3]))
9966
        )
9967
        ) begin
9968
              iqentry_fpu_issue[head5] = `TRUE;
9969
              iqentry_fpu_islot[head5] = slot;
9970
    end
9971
    else if (could_issue[head6] && iqentry_fpu[head6]
9972
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
9973
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
9974
                ((!iqentry_v[head0])
9975
        &&   (!iqentry_v[head1]))
9976
        )
9977
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
9978
                ((!iqentry_v[head0])
9979
        &&   (!iqentry_v[head1])
9980
        &&   (!iqentry_v[head2]))
9981
        )
9982
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
9983
                ((!iqentry_v[head0])
9984
        &&   (!iqentry_v[head1])
9985
        &&   (!iqentry_v[head2])
9986
        &&   (!iqentry_v[head3]))
9987
        )
9988
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
9989
                ((!iqentry_v[head0])
9990
        &&   (!iqentry_v[head1])
9991
        &&   (!iqentry_v[head2])
9992
        &&   (!iqentry_v[head3])
9993
        &&   (!iqentry_v[head4]))
9994
        )
9995
    ) begin
9996
        iqentry_fpu_issue[head6] = `TRUE;
9997
            iqentry_fpu_islot[head6] = slot;
9998
    end
9999
    else if (could_issue[head7] && iqentry_fpu[head7]
10000
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
10001
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
10002
                ((!iqentry_v[head0])
10003
        &&   (!iqentry_v[head1]))
10004
        )
10005
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
10006
                ((!iqentry_v[head0])
10007
        &&   (!iqentry_v[head1])
10008
        &&   (!iqentry_v[head2]))
10009
        )
10010
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
10011
                ((!iqentry_v[head0])
10012
        &&   (!iqentry_v[head1])
10013
        &&   (!iqentry_v[head2])
10014
        &&   (!iqentry_v[head3]))
10015
        )
10016
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
10017
                ((!iqentry_v[head0])
10018
        &&   (!iqentry_v[head1])
10019
        &&   (!iqentry_v[head2])
10020
        &&   (!iqentry_v[head3])
10021
        &&   (!iqentry_v[head4]))
10022
        )
10023
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
10024
                ((!iqentry_v[head0])
10025
        &&   (!iqentry_v[head1])
10026
        &&   (!iqentry_v[head2])
10027
        &&   (!iqentry_v[head3])
10028
        &&   (!iqentry_v[head4])
10029
        &&   (!iqentry_v[head5]))
10030
        )
10031
        )
10032
    begin
10033
                iqentry_fpu_issue[head7] = `TRUE;
10034
                iqentry_fpu_islot[head7] = slot;
10035
        end
10036
        end
10037
end
10038
endtask
10039
*/
10040
endmodule
10041
 
10042
 
10043
module decoder5 (num, out);
10044
input [4:0] num;
10045
output [31:1] out;
10046
reg [31:1] out;
10047
 
10048
always @(num)
10049
case (num)
10050
    5'd0 :      out <= 31'b0000000000000000000000000000000;
10051
    5'd1 :      out <= 31'b0000000000000000000000000000001;
10052
    5'd2 :      out <= 31'b0000000000000000000000000000010;
10053
    5'd3 :      out <= 31'b0000000000000000000000000000100;
10054
    5'd4 :      out <= 31'b0000000000000000000000000001000;
10055
    5'd5 :      out <= 31'b0000000000000000000000000010000;
10056
    5'd6 :      out <= 31'b0000000000000000000000000100000;
10057
    5'd7 :      out <= 31'b0000000000000000000000001000000;
10058
    5'd8 :      out <= 31'b0000000000000000000000010000000;
10059
    5'd9 :      out <= 31'b0000000000000000000000100000000;
10060
    5'd10:      out <= 31'b0000000000000000000001000000000;
10061
    5'd11:      out <= 31'b0000000000000000000010000000000;
10062
    5'd12:      out <= 31'b0000000000000000000100000000000;
10063
    5'd13:      out <= 31'b0000000000000000001000000000000;
10064
    5'd14:      out <= 31'b0000000000000000010000000000000;
10065
    5'd15:      out <= 31'b0000000000000000100000000000000;
10066
    5'd16:      out <= 31'b0000000000000001000000000000000;
10067
    5'd17:      out <= 31'b0000000000000010000000000000000;
10068
    5'd18:      out <= 31'b0000000000000100000000000000000;
10069
    5'd19:      out <= 31'b0000000000001000000000000000000;
10070
    5'd20:      out <= 31'b0000000000010000000000000000000;
10071
    5'd21:      out <= 31'b0000000000100000000000000000000;
10072
    5'd22:      out <= 31'b0000000001000000000000000000000;
10073
    5'd23:      out <= 31'b0000000010000000000000000000000;
10074
    5'd24:      out <= 31'b0000000100000000000000000000000;
10075
    5'd25:      out <= 31'b0000001000000000000000000000000;
10076
    5'd26:      out <= 31'b0000010000000000000000000000000;
10077
    5'd27:      out <= 31'b0000100000000000000000000000000;
10078
    5'd28:      out <= 31'b0001000000000000000000000000000;
10079
    5'd29:      out <= 31'b0010000000000000000000000000000;
10080
    5'd30:      out <= 31'b0100000000000000000000000000000;
10081
    5'd31:      out <= 31'b1000000000000000000000000000000;
10082
endcase
10083
 
10084
endmodule
10085
 
10086
module decoder6 (num, out);
10087
input [5:0] num;
10088
output [63:1] out;
10089
 
10090
wire [63:0] out1;
10091
 
10092
assign out1 = 64'd1 << num;
10093
assign out = out1[63:1];
10094
 
10095
endmodule
10096
 
10097
module decoder7 (num, out);
10098
input [6:0] num;
10099
output [127:1] out;
10100
 
10101
wire [127:0] out1;
10102
 
10103
assign out1 = 128'd1 << num;
10104
assign out = out1[127:1];
10105
 
10106
endmodule
10107
 
10108
module decoder8 (num, out);
10109
input [7:0] num;
10110
output [255:1] out;
10111
 
10112
wire [255:0] out1;
10113
 
10114
assign out1 = 256'd1 << num;
10115
assign out = out1[255:1];
10116
 
10117
endmodule
10118
 

powered by: WebSVN 2.1.0

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