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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v7/] [rtl/] [twoway/] [FT64_fetchbuf.v] - Blame information for rev 61

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 60 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2017-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      FT64_fetchbuf.v
9
//
10
// This source file is free software: you can redistribute it and/or modify 
11
// it under the terms of the GNU Lesser General Public License as published 
12
// by the Free Software Foundation, either version 3 of the License, or     
13
// (at your option) any later version.                                      
14
//                                                                          
15
// This source file is distributed in the hope that it will be useful,      
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
18
// GNU General Public License for more details.                             
19
//                                                                          
20
// You should have received a copy of the GNU General Public License        
21
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
22
//
23
// ============================================================================
24
//
25
`include "FT64_config.vh"
26
`include "FT64_defines.vh"
27
 
28
// FETCH
29
//
30
// fetch exactly two instructions from memory into the fetch buffer
31
// unless either one of the buffers is still full, in which case we
32
// do nothing (kinda like alpha approach)
33
// Like to turn this into an independent module at some point.
34
//
35
module FT64_fetchbuf(rst, clk4x, clk, fcu_clk,
36
        cs_i, cyc_i, stb_i, ack_o, we_i, adr_i, dat_i,
37
        cmpgrp,
38
        freezePC, thread_en,
39
        regLR,
40
    insn0, insn1, phit,
41
    threadx,
42
    branchmiss, misspc, branchmiss_thrd, predict_taken0, predict_taken1,
43
    predict_takenA, predict_takenB, predict_takenC, predict_takenD,
44
    queued1, queued2, queuedNop,
45
    pc0, pc1, fetchbuf, fetchbufA_v, fetchbufB_v, fetchbufC_v, fetchbufD_v,
46
    fetchbufA_instr, fetchbufA_pc,
47
    fetchbufB_instr, fetchbufB_pc,
48
    fetchbufC_instr, fetchbufC_pc,
49
    fetchbufD_instr, fetchbufD_pc,
50
    fetchbuf0_instr, fetchbuf1_instr, fetchbuf0_insln, fetchbuf1_insln,
51
    fetchbuf0_thrd, fetchbuf1_thrd,
52
    fetchbuf0_pc, fetchbuf1_pc,
53
    fetchbuf0_v, fetchbuf1_v,
54
    codebuf0, codebuf1,
55
    btgtA, btgtB, btgtC, btgtD,
56
    nop_fetchbuf,
57
    take_branch0, take_branch1,
58
    stompedRets,
59 61 robfinch
    pred_on,
60 60 robfinch
    panic
61
);
62
parameter AMSB = `AMSB;
63
parameter RSTPC = 64'hFFFC0100;
64
parameter TRUE = 1'b1;
65
parameter FALSE = 1'b0;
66
input rst;
67
input clk4x;
68
input clk;
69
input fcu_clk;
70
input cs_i;
71
input cyc_i;
72
input stb_i;
73
output ack_o;
74
input we_i;
75
input [15:0] adr_i;
76
input [47:0] dat_i;
77
input [2:0] cmpgrp;
78
input freezePC;
79
input thread_en;
80
input [4:0] regLR;
81
input [47:0] insn0;
82
input [47:0] insn1;
83
input phit;
84
output threadx;
85
input branchmiss;
86
input [AMSB:0] misspc;
87
input branchmiss_thrd;
88
output predict_taken0;
89
output predict_taken1;
90
input predict_takenA;
91
input predict_takenB;
92
input predict_takenC;
93
input predict_takenD;
94
input queued1;
95
input queued2;
96
input queuedNop;
97
output reg [AMSB:0] pc0;
98
output reg [AMSB:0] pc1;
99
output reg fetchbuf;
100
output reg fetchbufA_v;
101
output reg fetchbufB_v;
102
output reg fetchbufC_v;
103
output reg fetchbufD_v;
104
output fetchbuf0_thrd;
105
output fetchbuf1_thrd;
106
output reg [47:0] fetchbufA_instr;
107
output reg [47:0] fetchbufB_instr;
108
output reg [47:0] fetchbufC_instr;
109
output reg [47:0] fetchbufD_instr;
110
output reg [AMSB:0] fetchbufA_pc;
111
output reg [AMSB:0] fetchbufB_pc;
112
output reg [AMSB:0] fetchbufC_pc;
113
output reg [AMSB:0] fetchbufD_pc;
114
output [47:0] fetchbuf0_instr;
115
output [47:0] fetchbuf1_instr;
116
output [AMSB:0] fetchbuf0_pc;
117
output [AMSB:0] fetchbuf1_pc;
118
output [2:0] fetchbuf0_insln;
119
output [2:0] fetchbuf1_insln;
120
output fetchbuf0_v;
121
output fetchbuf1_v;
122
input [47:0] codebuf0;
123
input [47:0] codebuf1;
124
input [AMSB:0] btgtA;
125
input [AMSB:0] btgtB;
126
input [AMSB:0] btgtC;
127
input [AMSB:0] btgtD;
128
input [3:0] nop_fetchbuf;
129
output take_branch0;
130
output take_branch1;
131
input [3:0] stompedRets;
132 61 robfinch
input pred_on;
133 60 robfinch
output reg [3:0] panic;
134
integer n;
135
 
136
//`include "FT64_decode.vh"
137
 
138
function IsBranch;
139
input [47:0] isn;
140
casex(isn[`INSTRUCTION_OP])
141
`Bcc:   IsBranch = TRUE;
142
`BBc:   IsBranch = TRUE;
143
`BEQI:  IsBranch = TRUE;
144
`BCHK:  IsBranch = TRUE;
145
default: IsBranch = FALSE;
146
endcase
147
endfunction
148
 
149
function IsJAL;
150
input [47:0] isn;
151
IsJAL = isn[`INSTRUCTION_OP]==`JAL;
152
endfunction
153
 
154
function IsJmp;
155
input [47:0] isn;
156
IsJmp = isn[`INSTRUCTION_OP]==`JMP;
157
endfunction
158
 
159
function IsCall;
160
input [47:0] isn;
161
IsCall = isn[`INSTRUCTION_OP]==`CALL;
162
endfunction
163
 
164
function IsRet;
165
input [47:0] isn;
166
IsRet = isn[`INSTRUCTION_OP]==`RET;
167
endfunction
168
 
169
function IsBrk;
170
input [47:0] isn;
171
IsBrk = isn[`INSTRUCTION_OP]==`BRK;
172
endfunction
173
 
174
function IsRTI;
175
input [47:0] isn;
176
IsRTI = isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_S2]==`RTI;
177
endfunction
178
 
179
 
180
function [2:0] fnInsLength;
181
input [47:0] ins;
182
`ifdef SUPPORT_DCI
183
if (ins[`INSTRUCTION_OP]==`CMPRSSD)
184
        fnInsLength = 3'd2;
185
else
186
`endif
187
        case(ins[7:6])
188 61 robfinch
        2'd0:   fnInsLength = 3'd4|pred_on;
189
        2'd1:   fnInsLength = 3'd6|pred_on;
190
        default:        fnInsLength = 3'd2|pred_on;
191 60 robfinch
        endcase
192
endfunction
193
 
194
wire [2:0] fetchbufA_inslen;
195
wire [2:0] fetchbufB_inslen;
196
wire [2:0] fetchbufC_inslen;
197
wire [2:0] fetchbufD_inslen;
198 61 robfinch
FT64_InsLength uilA (fetchbufA_instr, fetchbufA_inslen, pred_on);
199
FT64_InsLength uilB (fetchbufB_instr, fetchbufB_inslen, pred_on);
200
FT64_InsLength uilC (fetchbufC_instr, fetchbufC_inslen, pred_on);
201
FT64_InsLength uilD (fetchbufD_instr, fetchbufD_inslen, pred_on);
202 60 robfinch
 
203
wire [47:0] xinsn0;
204
wire [47:0] xinsn1;
205
 
206
FT64_iexpander ux1
207
(
208
        .cinstr(insn0[15:0]),
209
        .expand(xinsn0)
210
);
211
FT64_iexpander ux2
212
(
213
        .cinstr(insn1[15:0]),
214
        .expand(xinsn1)
215
);
216
 
217
 
218
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
219
// Table of decompressed instructions.
220
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
221
assign ack_o = cs_i & cyc_i & stb_i;
222
`ifdef SUPPORT_DCI
223
reg [47:0] DecompressTable [0:2047];
224
always @(posedge clk)
225
        if (cs_i & cyc_i & stb_i & we_i)
226
                DecompressTable[adr_i[12:3]] <= dat_i[47:0];
227
wire [47:0] expand0 = DecompressTable[{cmpgrp,insn0[15:8]}];
228
wire [47:0] expand1 = DecompressTable[{cmpgrp,insn1[15:8]}];
229
`endif
230
 
231
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
232
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
233
 
234
reg thread;
235
reg stompedRet;
236
reg ret0Counted, ret1Counted;
237
wire [AMSB:0] retpc0, retpc1;
238
 
239
reg did_branchback0;
240
reg did_branchback1;
241
 
242
assign predict_taken0 = (fetchbuf==1'b0) ? predict_takenA : predict_takenC;
243
assign predict_taken1 = (fetchbuf==1'b0) ? predict_takenB : predict_takenD;
244
 
245
reg [AMSB:0] branch_pcA;
246
reg [AMSB:0] branch_pcB;
247
reg [AMSB:0] branch_pcC;
248
reg [AMSB:0] branch_pcD;
249
 
250
always @*
251
case(fetchbufA_instr[`INSTRUCTION_OP])
252
`RET:           branch_pcA = retpc0;
253
`JMP,`CALL: branch_pcA = fetchbufA_instr[6] ? {fetchbufA_instr[39:8],1'b0} : {fetchbufA_pc[31:25],fetchbufA_instr[31:8],1'b0};
254
`R2:            branch_pcA = btgtA;     // RTI
255
`BRK,`JAL:      branch_pcA = btgtA;
256
default:
257
        begin
258
        branch_pcA[31:8] = fetchbufA_pc[31:8] +
259
                (fetchbufA_instr[7:6]==2'b01 ? {{4{fetchbufA_instr[47]}},fetchbufA_instr[47:28]} : {{20{fetchbufA_instr[31]}},fetchbufA_instr[31:28]});
260
        branch_pcA[7:0] = {fetchbufA_instr[27:23],fetchbufA_instr[17:16],1'b0};
261
        branch_pcA[63:32] = fetchbufA_pc[63:32];
262
        end
263
endcase
264
 
265
always @*
266
case(fetchbufB_instr[`INSTRUCTION_OP])
267
`RET:           branch_pcB = retpc1;
268
`JMP,`CALL: branch_pcB = fetchbufB_instr[6] ? {fetchbufB_instr[39:8],1'b0} : {fetchbufB_pc[31:25],fetchbufB_instr[31:8],1'b0};
269
`R2:            branch_pcB = btgtB;     // RTI
270
`BRK,`JAL:      branch_pcB = btgtB;
271
default:
272
        begin
273
        branch_pcB[31:8] = fetchbufB_pc[31:8] +
274
                (fetchbufB_instr[7:6]==2'b01 ? {{4{fetchbufB_instr[47]}},fetchbufB_instr[47:28]} : {{20{fetchbufB_instr[31]}},fetchbufB_instr[31:28]});
275
        branch_pcB[7:0] = {fetchbufB_instr[27:23],fetchbufB_instr[17:16],1'b0};
276
        branch_pcB[63:32] = fetchbufB_pc[63:32];
277
        end
278
endcase
279
 
280
always @*
281
case(fetchbufC_instr[`INSTRUCTION_OP])
282
`RET:           branch_pcC = retpc0;
283
`JMP,`CALL: branch_pcC = fetchbufC_instr[6] ? {fetchbufC_instr[39:8],1'b0} : {fetchbufC_pc[31:25],fetchbufC_instr[31:8],1'b0};
284
`R2:            branch_pcC = btgtC;     // RTI
285
`BRK,`JAL:      branch_pcC = btgtC;
286
default:
287
        begin
288
        branch_pcC[31:8] = fetchbufC_pc[31:8] +
289
                (fetchbufC_instr[7:6]==2'b01 ? {{4{fetchbufC_instr[47]}},fetchbufC_instr[47:28]} : {{20{fetchbufC_instr[31]}},fetchbufC_instr[31:28]});
290
        branch_pcC[7:0] = {fetchbufC_instr[27:23],fetchbufC_instr[17:16],1'b0};
291
        branch_pcC[63:32] = fetchbufC_pc[63:32];
292
        end
293
endcase
294
 
295
always @*
296
case(fetchbufD_instr[`INSTRUCTION_OP])
297
`RET:           branch_pcD = retpc1;
298
`JMP,`CALL: branch_pcD = fetchbufD_instr[6] ? {fetchbufD_instr[39:8],1'b0} : {fetchbufD_pc[31:25],fetchbufD_instr[31:8],1'b0};
299
`R2:            branch_pcD = btgtD;     // RTI
300
`BRK,`JAL:      branch_pcD = btgtD;
301
default:
302
        begin
303
        branch_pcD[31:8] = fetchbufD_pc[31:8] +
304
                (fetchbufD_instr[7:6]==2'b01 ? {{4{fetchbufD_instr[47]}},fetchbufD_instr[47:28]} : {{20{fetchbufD_instr[31]}},fetchbufD_instr[31:28]});
305
        branch_pcD[7:0] = {fetchbufD_instr[27:23],fetchbufD_instr[17:16],1'b0};
306
        branch_pcD[63:32] = fetchbufD_pc[63:32];
307
        end
308
endcase
309
 
310
wire take_branchA = ({fetchbufA_v, IsBranch(fetchbufA_instr), predict_takenA}  == {`VAL, `TRUE, `TRUE}) ||
311
                        ((IsRet(fetchbufA_instr)||IsJmp(fetchbufA_instr)||IsCall(fetchbufA_instr)||
312
                        IsRTI(fetchbufA_instr)|| IsBrk(fetchbufA_instr) || IsJAL(fetchbufA_instr)) &&
313
                        fetchbufA_v);
314
wire take_branchB = ({fetchbufB_v, IsBranch(fetchbufB_instr), predict_takenB}  == {`VAL, `TRUE, `TRUE}) ||
315
                        ((IsRet(fetchbufB_instr)|IsJmp(fetchbufB_instr)|IsCall(fetchbufB_instr) ||
316
                        IsRTI(fetchbufB_instr)|| IsBrk(fetchbufB_instr) || IsJAL(fetchbufB_instr)) &&
317
                        fetchbufB_v);
318
wire take_branchC = ({fetchbufC_v, IsBranch(fetchbufC_instr), predict_takenC}  == {`VAL, `TRUE, `TRUE}) ||
319
                        ((IsRet(fetchbufC_instr)|IsJmp(fetchbufC_instr)|IsCall(fetchbufC_instr) ||
320
                        IsRTI(fetchbufC_instr)|| IsBrk(fetchbufC_instr) || IsJAL(fetchbufC_instr)) &&
321
                        fetchbufC_v);
322
wire take_branchD = ({fetchbufD_v, IsBranch(fetchbufD_instr), predict_takenD}  == {`VAL, `TRUE, `TRUE}) ||
323
                        ((IsRet(fetchbufD_instr)|IsJmp(fetchbufD_instr)|IsCall(fetchbufD_instr) ||
324
                        IsRTI(fetchbufD_instr)|| IsBrk(fetchbufD_instr) || IsJAL(fetchbufD_instr)) &&
325
                        fetchbufD_v);
326
 
327
assign take_branch0 = fetchbuf==1'b0 ? take_branchA : take_branchC;
328
assign take_branch1 = fetchbuf==1'b0 ? take_branchB : take_branchD;
329
wire take_branch = take_branch0 || take_branch1;
330
/*
331
always @*
332
begin
333
        pc0 <= thread_en ? (fetchbuf ? pc0b : pc0a) : pc0a;
334
        pc1 <= thread_en ? (fetchbuf ? pc1b : pc1a) : pc1a;
335
end
336
*/
337
assign threadx = fetchbuf;
338
 
339
`ifdef FCU_ENH
340
FT64_RSB #(AMSB) ursb1
341
(
342
        .rst(rst),
343
        .clk(fcu_clk),
344
        .regLR(regLR),
345
        .queued1(queued1),
346
        .queued2(queued2),
347
        .fetchbuf0_v(fetchbuf0_v),
348
        .fetchbuf0_pc(fetchbuf0_pc),
349
        .fetchbuf0_instr(fetchbuf0_instr),
350
        .fetchbuf1_v(fetchbuf1_v),
351
        .fetchbuf1_pc(fetchbuf1_pc),
352
        .fetchbuf1_instr(fetchbuf1_instr),
353
        .stompedRets(stompedRets),
354
        .stompedRet(stompedRet),
355
        .pc(retpc0)
356
);
357
 
358
FT64_RSB #(AMSB) ursb2
359
(
360
        .rst(rst),
361
        .clk(fcu_clk),
362
        .regLR(regLR),
363
        .queued1(queued1),
364
        .queued2(1'b0),
365
        .fetchbuf0_v(fetchbuf1_v),
366
        .fetchbuf0_pc(fetchbuf1_pc),
367
        .fetchbuf0_instr(fetchbuf1_instr),
368
        .fetchbuf1_v(1'b0),
369
        .fetchbuf1_pc(32'h00000000),
370
        .fetchbuf1_instr(`NOP_INSN),
371
        .stompedRets(stompedRets[3:1]),
372
        .stompedRet(stompedRet),
373
        .pc(retpc1)
374
);
375
`else
376
assign retpc0 = RSTPC;
377
assign retpc1 = RSTPC;
378
`endif
379
 
380
wire peclk, neclk;
381
edge_det ued1 (.rst(rst), .clk(clk4x), .ce(1'b1), .i(clk), .pe(peclk), .ne(neclk), .ee());
382
 
383
always @(posedge clk)
384
if (rst) begin
385
        pc0 <= RSTPC;
386
  pc1 <= RSTPC;
387
        fetchbufA_v <= 0;
388
        fetchbufB_v <= 0;
389
        fetchbufC_v <= 0;
390
        fetchbufD_v <= 0;
391
        fetchbuf <= 0;
392
        panic <= `PANIC_NONE;
393
end
394
else begin
395
 
396
        did_branchback0 <= take_branch0;
397
        did_branchback1 <= take_branch1;
398
 
399
        stompedRet = FALSE;
400
 
401
        begin
402
 
403
        // On a branch miss with threading enabled all fectch buffers are
404
        // invalidated even though the data in the fetch buffer would be valid
405
        // for the thread that isn't in a branchmiss state. This is done to
406
        // keep things simple. For the thread that doesn't miss the current
407
        // data for the fetch buffer needs to be retrieved again, so the pc
408
        // for that thread is assigned the current fetchbuf pc.
409
        // For the thread that misses the pc is simply assigned the misspc.
410
        if (branchmiss) begin
411
                $display("***********");
412
                $display("Branch miss");
413
                $display("***********");
414
                if (branchmiss_thrd) begin
415
                        pc1 <= misspc;
416
                        fetchbufB_v <= `INV;
417
                        fetchbufD_v <= `INV;
418
                end
419
                else begin
420
                        pc0 <= misspc;
421
                        if (thread_en) begin
422
                                fetchbufA_v <= `INV;
423
                                fetchbufC_v <= `INV;
424
                        end
425
                        else begin
426
                                fetchbufA_v <= `INV;
427
                                fetchbufB_v <= `INV;
428
                                fetchbufC_v <= `INV;
429
                                fetchbufD_v <= `INV;
430
                                fetchbuf <= 1'b0;
431
                        end
432
                end
433
             $display("********************");
434
             $display("********************");
435
             $display("********************");
436
             $display("Branch miss");
437
             $display("misspc=%h", misspc);
438
             $display("********************");
439
             $display("********************");
440
             $display("********************");
441
        end
442
        else if (take_branch) begin
443
 
444
    // update the fetchbuf valid bits as well as fetchbuf itself
445
    // ... this must be based on which things are backwards branches, how many things
446
    // will get enqueued (0, 1, or 2), and how old the instructions are
447
    if (fetchbuf == 1'b0) case ({fetchbufA_v, fetchbufB_v, fetchbufC_v, fetchbufD_v})
448
 
449
                4'b0000: ;      // do nothing
450
                4'b0001: if (thread_en) FetchC();
451
                4'b0010: if (thread_en) FetchD();
452
                4'b0011: ;
453
                4'b0100 :
454
            begin
455
                    if (thread_en) begin
456
                        FetchC();
457
                        pc1 <= branch_pcB;
458
                    end
459
                    else
460
                        pc0 <= branch_pcB;
461
                    fetchbufB_v <= !(queued1|queuedNop);        // if it can be queued, it will
462
                    fetchbuf <= fetchbuf + (queued1|queuedNop);
463
                        end
464
                4'b0101:
465
                        begin
466
                                if (thread_en) begin
467
                                        pc1 <= branch_pcB;
468
                                        FetchC();
469
                                end
470
                                else
471
                                        pc0 <= branch_pcB;
472
                                fetchbufD_v <= `INV;
473
                                fetchbufB_v <= !(queued1|queuedNop);
474
                        end
475
                4'b0110:
476
                        begin
477
                                if (thread_en)
478
                                        pc1 <= branch_pcB;
479
                                else begin
480
                                        pc0 <= branch_pcB;
481
                                        fetchbufC_v <= `INV;
482
                                end
483
                                fetchbufB_v <= !(queued1|queuedNop);
484
                        end
485
                4'b0111:
486
                        begin
487
                                if (thread_en) begin
488
                                        pc1 <= branch_pcB;
489
                                        fetchbufD_v <= `INV;
490
                                end
491
                                else begin
492
                                        pc0 <= branch_pcB;
493
                                        fetchbufC_v <= `INV;
494
                                        fetchbufD_v <= `INV;
495
                                end
496
                          fetchbufB_v <= !(queued1|queuedNop);  // if it can be queued, it will
497
                                fetchbuf <= fetchbuf + (queued1|queuedNop);
498
                        end
499
                4'b1000 :
500
                        begin
501
                                if (thread_en) FetchD();
502
                    pc0 <= branch_pcA;
503
                    fetchbufA_v <= !(queued1|queuedNop);        // if it can be queued, it will
504
                    fetchbuf <= fetchbuf + (queued1|queuedNop);
505
                        end
506
                4'b1001:
507
                        begin
508
                                pc0 <= branch_pcA;
509
                                if (!thread_en)
510
                                        fetchbufD_v <= `INV;
511
                    fetchbufA_v <= !(queued1|queuedNop);        // if it can be queued, it will
512
                    fetchbuf <= fetchbuf + (queued1|queuedNop);
513
                        end
514
                4'b1010:
515
                        begin
516
                                pc0 <= branch_pcA;
517
                                fetchbufC_v <= `INV;
518
                                if (thread_en) FetchD();
519
                    fetchbufA_v <= !(queued1|queuedNop);        // if it can be queued, it will
520
                    fetchbuf <= fetchbuf + (queued1|queuedNop);
521
                        end
522
                4'b1011:
523
                        begin
524
                                pc0 <= branch_pcA;
525
                                fetchbufC_v <= `INV;
526
                                if (!thread_en)
527
                                        fetchbufD_v <= `INV;
528
                                fetchbufA_v <=!(queued1|queuedNop);     // if it can be queued, it will
529
                                fetchbuf <= fetchbuf + (queued1|queuedNop);
530
                        end
531
                4'b1100:
532
                        if (thread_en) begin
533
                                if (take_branchA && take_branchB) begin
534
                                        pc0 <= branch_pcA;
535
                                        pc1 <= branch_pcB;
536
                                        fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
537
                                        fetchbufB_v <= !(queued2|queuedNop);    // if it can be queued, it will
538
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
539
                                end
540
                                else if (take_branchA) begin
541
                                        FetchD();
542
                                        pc0 <= branch_pcA;
543
                                        fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
544
                                        fetchbufB_v <= !(queued2|queuedNop);    // if it can be queued, it will
545
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
546
                                end
547
                                else if (take_branchB) begin
548
                                        FetchC();
549
                                        pc1 <= branch_pcB;
550
                                        fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
551
                                        fetchbufB_v <= !(queued2|queuedNop);    // if it can be queued, it will
552
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
553
                                end
554
                        end
555
                        else begin
556
                                if (take_branchA) begin
557
                                        pc0 <= branch_pcA;
558
                                        fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
559
                                        fetchbufB_v <= `INV;
560
                                        if ((queued1|queuedNop))   fetchbuf <= 1'b1;
561
                                end
562
                                else if (take_branchB) begin
563
                                        pc0 <= branch_pcB;
564
                                        fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
565
                                        fetchbufB_v <= !(queued2|queuedNop);    // if it can be queued, it will
566
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
567
                    end
568
                    // else hardware error
569
                  end
570
                4'b1101:
571
                        if (thread_en) begin
572
                                if (take_branchA && take_branchB) begin
573
                                        pc0 <= branch_pcA;
574
                                        pc1 <= branch_pcB;
575
                                        fetchbufD_v <= `INV;
576
                                        fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
577
                                        fetchbufB_v <= !(queued2|queuedNop);    // if it can be queued, it will
578
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
579
                                end
580
                                else if (take_branchA) begin
581
                                        pc0 <= branch_pcA;
582
                                        fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
583
                                        fetchbufB_v <= !(queued2|queuedNop);    // if it can be queued, it will
584
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
585
                                end
586
                                else if (take_branchB) begin
587
                                        FetchC();
588
                                        pc1 <= branch_pcB;
589
                                        fetchbufD_v <= `INV;
590
                                        fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
591
                                        fetchbufB_v <= !(queued2|queuedNop);    // if it can be queued, it will
592
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
593
                                end
594
                        end
595
                        else begin
596
                                fetchbufD_v <= `INV;
597
                                if (take_branchA) begin
598
                                        pc0 <= branch_pcA;
599
                                        fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
600
                                        fetchbufB_v <= `INV;
601
                                        if ((queued1|queuedNop))   fetchbuf <= 1'b1;
602
                                end
603
                                else if (take_branchB) begin
604
                                        pc0 <= branch_pcB;
605
                                        fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
606
                                        fetchbufB_v <= !(queued2|queuedNop);    // if it can be queued, it will
607
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
608
                    end
609
                    // else hardware error
610
                  end
611
                4'b1110:
612
                        if (thread_en) begin
613
                                if (take_branchA && take_branchB) begin
614
                                        pc0 <= branch_pcA;
615
                                        pc1 <= branch_pcB;
616
                                        fetchbufC_v <= `INV;
617
                                        fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
618
                                        fetchbufB_v <= !(queued2|queuedNop);    // if it can be queued, it will
619
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
620
                                end
621
                                else if (take_branchA) begin
622
                                        FetchD();
623
                                        pc0 <= branch_pcA;
624
                                        fetchbufC_v <= `INV;
625
                                        fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
626
                                        fetchbufB_v <= !(queued2|queuedNop);    // if it can be queued, it will
627
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
628
                                end
629
                                else if (take_branchB) begin
630
                                        pc1 <= branch_pcB;
631
                                        fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
632
                                        fetchbufB_v <= !(queued2|queuedNop);    // if it can be queued, it will
633
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
634
                                end
635
                        end
636
                        else begin
637
                                fetchbufC_v <= `INV;
638
                                if (take_branchA) begin
639
                                        pc0 <= branch_pcA;
640
                                        fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
641
                                        fetchbufB_v <= `INV;
642
                                        if ((queued1|queuedNop))   fetchbuf <= 1'b1;
643
                                end
644
                                else if (take_branchB) begin
645
                                        pc0 <= branch_pcB;
646
                                        fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
647
                                        fetchbufB_v <= !(queued2|queuedNop);    // if it can be queued, it will
648
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
649
                    end
650
                    // else hardware error
651
                  end
652
                4'b1111:
653
                        begin
654
                                if (thread_en) begin
655
                                        if (take_branchA & take_branchB) begin
656
                                                pc0 <= branch_pcA;
657
                                                pc1 <= branch_pcB;
658
                                                fetchbufC_v <= `INV;
659
                                                fetchbufD_v <= `INV;
660
                                                fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
661
                                                fetchbufB_v <= !(queued2|queuedNop);    // if it can be queued, it will
662
                                                fetchbuf <= fetchbuf + (queued2|queuedNop);
663
                                        end
664
                                        else if (take_branchA) begin
665
                                                pc0 <= branch_pcA;
666
                                                fetchbufC_v <= `INV;
667
                                                fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
668
                                                fetchbufB_v <= !(queued2|queuedNop);    // if it can be queued, it will
669
                                                fetchbuf <= fetchbuf + (queued2|queuedNop);
670
                                        end
671
                                        else if (take_branchB) begin
672
                                                pc1 <= branch_pcB;
673
                                                fetchbufD_v <= `INV;
674
                                                fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
675
                                                fetchbufB_v <= !(queued2|queuedNop);    // if it can be queued, it will
676
                                                fetchbuf <= fetchbuf + (queued2|queuedNop);
677
                                        end
678
                                end
679
                                else begin
680
                                        if (take_branchA) begin
681
                                                pc0 <= branch_pcA;
682
                                                fetchbufB_v <= `INV;
683
                                                fetchbufC_v <= `INV;
684
                                                fetchbufD_v <= `INV;
685
                                                fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
686
                                                fetchbuf <= fetchbuf + (queued1|queuedNop);
687
                                        end
688
                                        else if (take_branchB) begin
689
                                                pc0 <= branch_pcB;
690
                                                fetchbufC_v <= `INV;
691
                                                fetchbufD_v <= `INV;
692
                                                fetchbufA_v <= !(queued1|queuedNop);    // if it can be queued, it will
693
                                                fetchbufB_v <= !(queued2|queuedNop);    // if it can be queued, it will
694
                                                fetchbuf <= fetchbuf + (queued2|queuedNop);
695
                                        end
696
                                end
697
                        end
698
    default:    ;
699
          endcase
700
          else case ({fetchbufC_v, fetchbufD_v, fetchbufA_v, fetchbufB_v})
701
 
702
                4'b0000: ;      // do nothing
703
                4'b0001: if (thread_en) FetchA();
704
                4'b0010: if (thread_en) FetchB();
705
                4'b0011: ;
706
                4'b0100 :
707
            begin
708
                    if (thread_en) begin
709
                        FetchA();
710
                        pc1 <= branch_pcD;
711
                    end
712
                    else
713
                        pc0 <= branch_pcD;
714
                    fetchbufD_v <= !(queued1|queuedNop);        // if it can be queued, it will
715
                    fetchbuf <= fetchbuf + (queued1|queuedNop);
716
                        end
717
                4'b0101:
718
                        begin
719
                                if (thread_en) begin
720
                                        pc1 <= branch_pcD;
721
                                        FetchA();
722
                                end
723
                                else
724
                                        pc0 <= branch_pcD;
725
                                fetchbufB_v <= `INV;
726
                                fetchbufD_v <= !(queued1|queuedNop);
727
                        end
728
                4'b0110:
729
                        begin
730
                                if (thread_en)
731
                                        pc1 <= branch_pcD;
732
                                else begin
733
                                        pc0 <= branch_pcD;
734
                                        fetchbufA_v <= `INV;
735
                                end
736
                                fetchbufD_v <= !(queued1|queuedNop);
737
                        end
738
                4'b0111:
739
                        begin
740
                                if (thread_en) begin
741
                                        pc1 <= branch_pcD;
742
                                        fetchbufB_v <= `INV;
743
                                end
744
                                else begin
745
                                        pc0 <= branch_pcD;
746
                                        fetchbufA_v <= `INV;
747
                                        fetchbufB_v <= `INV;
748
                                end
749
                          fetchbufD_v <= !(queued1|queuedNop);  // if it can be queued, it will
750
                                fetchbuf <= fetchbuf + (queued1|queuedNop);
751
                        end
752
                4'b1000 :
753
                        begin
754
                                if (thread_en) FetchB();
755
                    pc0 <= branch_pcC;
756
                    fetchbufC_v <= !(queued1|queuedNop);        // if it can be queued, it will
757
                    fetchbuf <= fetchbuf + (queued1|queuedNop);
758
                        end
759
                4'b1001:
760
                        begin
761
                                pc0 <= branch_pcC;
762
                                if (!thread_en)
763
                                        fetchbufB_v <= `INV;
764
                    fetchbufC_v <= !(queued1|queuedNop);        // if it can be queued, it will
765
                    fetchbuf <= fetchbuf + (queued1|queuedNop);
766
                        end
767
                4'b1010:
768
                        begin
769
                                pc0 <= branch_pcC;
770
                                fetchbufA_v <= `INV;
771
                                if (thread_en) FetchB();
772
                    fetchbufC_v <= !(queued1|queuedNop);        // if it can be queued, it will
773
                    fetchbuf <= fetchbuf + (queued1|queuedNop);
774
                        end
775
                4'b1011:
776
                        begin
777
                                pc0 <= branch_pcC;
778
                                fetchbufA_v <= `INV;
779
                                if (!thread_en)
780
                                        fetchbufB_v <= `INV;
781
                                fetchbufC_v <=!(queued1|queuedNop);     // if it can be queued, it will
782
                                fetchbuf <= fetchbuf + (queued1|queuedNop);
783
                        end
784
                4'b1100:
785
                        if (thread_en) begin
786
                                if (take_branchC && take_branchD) begin
787
                                        pc0 <= branch_pcC;
788
                                        pc1 <= branch_pcD;
789
                                        fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
790
                                        fetchbufD_v <= !(queued2|queuedNop);    // if it can be queued, it will
791
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
792
                                end
793
                                else if (take_branchC) begin
794
                                        FetchB();
795
                                        pc0 <= branch_pcC;
796
                                        fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
797
                                        fetchbufD_v <= !(queued2|queuedNop);    // if it can be queued, it will
798
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
799
                                end
800
                                else if (take_branchD) begin
801
                                        FetchA();
802
                                        pc1 <= branch_pcD;
803
                                        fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
804
                                        fetchbufD_v <= !(queued2|queuedNop);    // if it can be queued, it will
805
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
806
                                end
807
                        end
808
                        else begin
809
                                if (take_branchC) begin
810
                                        pc0 <= branch_pcC;
811
                                        fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
812
                                        fetchbufD_v <= `INV;
813
                                        if ((queued1|queuedNop))   fetchbuf <= 1'b1;
814
                                end
815
                                else if (take_branchD) begin
816
                                        pc0 <= branch_pcD;
817
                                        fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
818
                                        fetchbufD_v <= !(queued2|queuedNop);    // if it can be queued, it will
819
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
820
                    end
821
                    // else hardware error
822
                  end
823
                4'b1101:
824
                        if (thread_en) begin
825
                                if (take_branchC && take_branchD) begin
826
                                        pc0 <= branch_pcC;
827
                                        pc1 <= branch_pcD;
828
                                        fetchbufB_v <= `INV;
829
                                        fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
830
                                        fetchbufD_v <= !(queued2|queuedNop);    // if it can be queued, it will
831
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
832
                                end
833
                                else if (take_branchC) begin
834
                                        pc0 <= branch_pcC;
835
                                        fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
836
                                        fetchbufD_v <= !(queued2|queuedNop);    // if it can be queued, it will
837
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
838
                                end
839
                                else if (take_branchC) begin
840
                                        FetchA();
841
                                        pc1 <= branch_pcD;
842
                                        fetchbufB_v <= `INV;
843
                                        fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
844
                                        fetchbufD_v <= !(queued2|queuedNop);    // if it can be queued, it will
845
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
846
                                end
847
                        end
848
                        else begin
849
                                fetchbufB_v <= `INV;
850
                                if (take_branchC) begin
851
                                        pc0 <= branch_pcC;
852
                                        fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
853
                                        fetchbufD_v <= `INV;
854
                                        if ((queued1|queuedNop))   fetchbuf <= 1'b1;
855
                                end
856
                                else if (take_branchD) begin
857
                                        pc0 <= branch_pcD;
858
                                        fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
859
                                        fetchbufD_v <= !(queued2|queuedNop);    // if it can be queued, it will
860
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
861
                    end
862
                    // else hardware error
863
                  end
864
                4'b1110:
865
                        if (thread_en) begin
866
                                if (take_branchC && take_branchD) begin
867
                                        pc0 <= branch_pcC;
868
                                        pc1 <= branch_pcD;
869
                                        fetchbufA_v <= `INV;
870
                                        fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
871
                                        fetchbufD_v <= !(queued2|queuedNop);    // if it can be queued, it will
872
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
873
                                end
874
                                else if (take_branchC) begin
875
                                        FetchB();
876
                                        pc0 <= branch_pcC;
877
                                        fetchbufA_v <= `INV;
878
                                        fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
879
                                        fetchbufD_v <= !(queued2|queuedNop);    // if it can be queued, it will
880
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
881
                                end
882
                                else if (take_branchD) begin
883
                                        pc1 <= branch_pcD;
884
                                        fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
885
                                        fetchbufD_v <= !(queued2|queuedNop);    // if it can be queued, it will
886
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
887
                                end
888
                        end
889
                        else begin
890
                                fetchbufA_v <= `INV;
891
                                if (take_branchC) begin
892
                                        pc0 <= branch_pcC;
893
                                        fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
894
                                        fetchbufD_v <= `INV;
895
                                        if ((queued1|queuedNop))   fetchbuf <= 1'b1;
896
                                end
897
                                else if (take_branchD) begin
898
                                        pc0 <= branch_pcD;
899
                                        fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
900
                                        fetchbufD_v <= !(queued2|queuedNop);    // if it can be queued, it will
901
                                        if ((queued2|queuedNop))   fetchbuf <= 1'b1;
902
                    end
903
                    // else hardware error
904
                  end
905
                4'b1111:
906
                        begin
907
                                if (thread_en) begin
908
                                        if (take_branchC & take_branchD) begin
909
                                                pc0 <= branch_pcC;
910
                                                pc1 <= branch_pcD;
911
                                                fetchbufA_v <= `INV;
912
                                                fetchbufB_v <= `INV;
913
                                                fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
914
                                                fetchbufD_v <= !(queued2|queuedNop);    // if it can be queued, it will
915
                                                fetchbuf <= fetchbuf + (queued2|queuedNop);
916
                                        end
917
                                        else if (take_branchC) begin
918
                                                pc0 <= branch_pcD;
919
                                                fetchbufA_v <= `INV;
920
                                                fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
921
                                                fetchbufD_v <= !(queued2|queuedNop);    // if it can be queued, it will
922
                                                fetchbuf <= fetchbuf + (queued2|queuedNop);
923
                                        end
924
                                        else if (take_branchD) begin
925
                                                pc1 <= branch_pcD;
926
                                                fetchbufB_v <= `INV;
927
                                                fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
928
                                                fetchbufD_v <= !(queued2|queuedNop);    // if it can be queued, it will
929
                                                fetchbuf <= fetchbuf + (queued2|queuedNop);
930
                                        end
931
                                end
932
                                else begin
933
                                        if (take_branchC) begin
934
                                                pc0 <= branch_pcC;
935
                                                fetchbufD_v <= `INV;
936
                                                fetchbufA_v <= `INV;
937
                                                fetchbufB_v <= `INV;
938
                                                fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
939
                                                fetchbuf <= fetchbuf + (queued1|queuedNop);
940
                                        end
941
                                        else if (take_branchD) begin
942
                                                pc0 <= branch_pcD;
943
                                                fetchbufA_v <= `INV;
944
                                                fetchbufB_v <= `INV;
945
                                                fetchbufC_v <= !(queued1|queuedNop);    // if it can be queued, it will
946
                                                fetchbufD_v <= !(queued2|queuedNop);    // if it can be queued, it will
947
                                                fetchbuf <= fetchbuf + (queued2|queuedNop);
948
                                        end
949
                                end
950
                        end
951
    default:    ;
952
          endcase
953
        end // if branchback
954
 
955
        else begin      // there is no branchback in the system
956
            //
957
            // update fetchbufX_v and fetchbuf ... relatively simple, as
958
            // there are no backwards branches in the mix
959
    if (fetchbuf == 1'b0) case ({fetchbufA_v, fetchbufB_v, (queued1|queuedNop), (queued2|queuedNop)})
960
                4'b00_00 : ;    // do nothing
961
                4'b00_01:       ;
962
                4'b00_10:       ;
963
                4'b00_11:       ;
964
                4'b01_00: ;     // do nothing
965
                4'b01_01:       ;
966
                4'b01_10,
967
                4'b01_11:
968
                        begin   // enqueue fbB and flip fetchbuf
969
                                fetchbufB_v <= `INV;
970
                          fetchbuf <= ~fetchbuf;
971
                  end
972
                4'b10_00: ;     // do nothing
973
                4'b10_01: ;
974
                4'b10_10,
975
                4'b10_11:
976
                        begin   // enqueue fbA and flip fetchbuf
977
                                fetchbufA_v <= `INV;
978
                          fetchbuf <= ~fetchbuf;
979
                  end
980
                4'b11_00: ;     // do nothing
981
                4'b11_01: ;
982
                4'b11_10:
983
                        begin   // enqueue fbA but leave fetchbuf
984
                                fetchbufA_v <= `INV;
985
                  end
986
                4'b11_11:
987
                        begin   // enqueue both and flip fetchbuf
988
                                fetchbufA_v <= `INV;
989
                                fetchbufB_v <= `INV;
990
                          fetchbuf <= ~fetchbuf;
991
                  end
992
                default:  panic <= `PANIC_INVALIDIQSTATE;
993
    endcase
994
    else case ({fetchbufC_v, fetchbufD_v, (queued1|queuedNop), (queued2|queuedNop)})
995
                4'b00_00 : ;    // do nothing
996
                4'b00_01: ;
997
                4'b00_10 : ;    // do nothing
998
                4'b00_11 : ;    // do nothing
999
                4'b01_00 : ;    // do nothing
1000
                4'b01_01 : ;
1001
                4'b01_10,
1002
                4'b01_11 :
1003
                        begin   // enqueue fbD and flip fetchbuf
1004
                                fetchbufD_v <= `INV;
1005
                          fetchbuf <= ~fetchbuf;
1006
                  end
1007
                4'b10_00 : ;    // do nothing
1008
                4'b10_01: ;
1009
                4'b10_10,
1010
                4'b10_11:
1011
                        begin   // enqueue fbC and flip fetchbuf
1012
                                fetchbufC_v <= `INV;
1013
                          fetchbuf <= ~fetchbuf;
1014
                  end
1015
                4'b11_00 : ;    // do nothing
1016
                4'b11_01: ;
1017
                4'b11_10:
1018
                        begin   // enqueue fbC but leave fetchbuf
1019
                                fetchbufC_v <= `INV;
1020
                  end
1021
                4'b11_11:
1022
                        begin   // enqueue both and flip fetchbuf
1023
                                fetchbufC_v <= `INV;
1024
                                fetchbufD_v <= `INV;
1025
                          fetchbuf <= ~fetchbuf;
1026
                  end
1027
                default:  panic <= `PANIC_INVALIDIQSTATE;
1028
          endcase
1029
    //
1030
    // get data iff the fetch buffers are empty
1031
    //
1032
    if (fetchbufA_v == `INV && fetchbufB_v == `INV) begin
1033
      FetchAB();
1034
      // fetchbuf steering logic correction
1035
      if (fetchbufC_v==`INV && fetchbufD_v==`INV && phit)
1036
        fetchbuf <= 1'b0;
1037
    end
1038
    else if (fetchbufC_v == `INV && fetchbufD_v == `INV)
1039
            FetchCD();
1040
        end
1041
    //
1042
    // get data iff the fetch buffers are empty
1043
    //
1044
    if (fetchbufA_v == `INV && fetchbufB_v == `INV && fetchbufC_v==`INV && fetchbufD_v==`INV) begin
1045
                        FetchAB();
1046
                        fetchbuf <= 1'b0;
1047
    end
1048
        end
1049
 
1050
        // The fetchbuffer is invalidated at the end of a vector instruction
1051
        // queue.
1052
        if (nop_fetchbuf[0])  fetchbufA_v <= `INV;
1053
        if (nop_fetchbuf[1])  fetchbufB_v <= `INV;
1054
        if (nop_fetchbuf[2])  fetchbufC_v <= `INV;
1055
        if (nop_fetchbuf[3])  fetchbufD_v <= `INV;
1056
end
1057
 
1058
assign fetchbuf0_instr = (fetchbuf == 1'b0) ? fetchbufA_instr : fetchbufC_instr;
1059
assign fetchbuf0_insln = (fetchbuf == 1'b0) ? fetchbufA_inslen: fetchbufC_inslen;
1060
assign fetchbuf0_v     = (fetchbuf == 1'b0) ? fetchbufA_v     : fetchbufC_v    ;
1061
assign fetchbuf0_pc    = (fetchbuf == 1'b0) ? fetchbufA_pc    : fetchbufC_pc   ;
1062
assign fetchbuf1_instr = (fetchbuf == 1'b0) ? fetchbufB_instr : fetchbufD_instr;
1063
assign fetchbuf1_insln = (fetchbuf == 1'b0) ? fetchbufB_inslen: fetchbufD_inslen;
1064
assign fetchbuf1_v     = (fetchbuf == 1'b0) ? fetchbufB_v     : fetchbufD_v    ;
1065
assign fetchbuf1_pc    = (fetchbuf == 1'b0) ? fetchbufB_pc    : fetchbufD_pc   ;
1066
assign fetchbuf0_thrd  = 1'b0;
1067
assign fetchbuf1_thrd  = thread_en;
1068
 
1069
reg [2:0] insln0, insln1;
1070
always @*
1071
begin
1072
`ifdef SUPPORT_DCI
1073
        if (insn0[5:0]==`CMPRSSD)
1074
                insln0 <= 3'd2;
1075
        else
1076
`endif
1077
        if (insn0[7:6]==2'b00 && insn0[`INSTRUCTION_OP]==`EXEC)
1078
                insln0 <= fnInsLength(codebuf0);
1079
        else
1080
                insln0 <= fnInsLength(insn0);
1081
end
1082
 
1083
always @*
1084
begin
1085
`ifdef SUPPORT_DCI
1086
        if (insn1[5:0]==`CMPRSSD)
1087
                insln1 <= 3'd2;
1088
        else
1089
`endif
1090
        if (insn1[7:6]==2'b00 && insn1[`INSTRUCTION_OP]==`EXEC)
1091
                insln1 <= fnInsLength(codebuf1);
1092
        else
1093
                insln1 <= fnInsLength(insn1);
1094
end
1095
 
1096
reg [47:0] cinsn0, cinsn1;
1097
 
1098
always @*
1099
begin
1100
`ifdef SUPPORT_DCI
1101
        if (insn0[5:0]==`CMPRSSD)
1102
                cinsn0 <= expand0;
1103
        else
1104
`endif
1105
        if (insn0[7:6]==2'b00 && insn0[`INSTRUCTION_OP]==`EXEC)
1106
                cinsn0 <= codebuf0;
1107
        else if (insn0[7])
1108
                cinsn0 <= xinsn0;
1109
        else
1110
                cinsn0 <= insn0;
1111
end
1112
 
1113
always @*
1114
begin
1115
`ifdef SUPPORT_DCI
1116
        if (insn1[5:0]==`CMPRSSD)
1117
                cinsn1 <= expand1;
1118
        else
1119
`endif
1120
        if (insn1[7:6]==2'b00 && insn1[`INSTRUCTION_OP]==`EXEC)
1121
                cinsn1 <= codebuf1;
1122
        else if (insn1[7])
1123
                cinsn1 <= xinsn1;
1124
        else
1125
                cinsn1 <= insn1;
1126
end
1127
 
1128
task FetchA;
1129
begin
1130
        fetchbufA_instr <= cinsn0;
1131
        fetchbufA_v <= `VAL;
1132
        fetchbufA_pc <= pc0;
1133
        if (phit && ~freezePC) begin
1134
                if (thread_en)
1135
                        pc0 <= pc0 + insln0;
1136
                else if (`WAYS > 1)
1137
                        pc0 <= pc0 + insln0 + insln1;
1138
                else
1139
                        pc0 <= pc0 + insln0;
1140
        end
1141
end
1142
endtask
1143
 
1144
task FetchB;
1145
begin
1146
        fetchbufB_instr <= cinsn1;
1147
        fetchbufB_v <= `WAYS > 1;
1148
        if (thread_en)
1149
                fetchbufB_pc <= pc1;
1150
        else
1151
                fetchbufB_pc <= pc0 + insln0;
1152
        if (phit & thread_en)
1153
                pc1 <= pc1 + insln1;
1154
end
1155
endtask
1156
 
1157
 
1158
task FetchAB;
1159
begin
1160
        FetchA();
1161
        FetchB();
1162
end
1163
endtask
1164
 
1165
task FetchC;
1166
begin
1167
        fetchbufC_instr <= cinsn0;
1168
        fetchbufC_v <= `VAL;
1169
        fetchbufC_pc <= pc0;
1170
        if (phit && ~freezePC) begin
1171
                if (thread_en)
1172
                        pc0 <= pc0 + insln0;
1173
                else if (`WAYS > 1)
1174
                        pc0 <= pc0 + insln0 + insln1;
1175
                else
1176
                        pc0 <= pc0 + insln0;
1177
        end
1178
end
1179
endtask
1180
 
1181
task FetchD;
1182
begin
1183
        fetchbufD_instr <= cinsn1;
1184
        fetchbufD_v <= `WAYS > 1;
1185
        if (thread_en)
1186
                fetchbufD_pc <= pc1;
1187
        else
1188
                fetchbufD_pc <= pc0 + insln0;
1189
        if (phit & thread_en)
1190
                pc1 <= pc1 + insln1;
1191
end
1192
endtask
1193
 
1194
task FetchCD;
1195
begin
1196
        FetchC();
1197
        FetchD();
1198
end
1199
endtask
1200
 
1201
endmodule
1202
 

powered by: WebSVN 2.1.0

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