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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v7/] [rtl/] [common/] [FT64_idecoder.v] - Blame information for rev 61

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 60 robfinch
// ============================================================================
2
//        __
3 61 robfinch
//   \\__/ o\    (C) 2017-2019  Robert Finch, Waterloo
4 60 robfinch
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      FT64_idecoder.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
module FT64_idecoder(clk,idv_i,id_i,instr,vl,ven,thrd,predict_taken,Rt,bus,id_o,idv_o,debug_on,pred_on);
29
input clk;
30
input idv_i;
31
input [4:0] id_i;
32
input [47:0] instr;
33
input [7:0] vl;
34
input [5:0] ven;
35
input thrd;
36
input predict_taken;
37
input [4:0] Rt;
38
output reg [143:0] bus;
39
output reg [4:0] id_o;
40
output reg idv_o;
41
input debug_on;
42
input pred_on;
43
 
44
parameter TRUE = 1'b1;
45
parameter FALSE = 1'b0;
46
// Memory access sizes
47
parameter byt = 3'd0;
48
parameter wyde = 3'd1;
49
parameter tetra = 3'd2;
50
parameter octa = 3'd3;
51 61 robfinch
parameter hexi = 3'd4;
52 60 robfinch
 
53
// Really IsPredictableBranch
54
// Does not include BccR's
55
//function IsBranch;
56
//input [47:0] isn;
57
//casez(isn[`INSTRUCTION_OP])
58
//`Bcc:   IsBranch = TRUE;
59
//`BBc:   IsBranch = TRUE;
60
//`BEQI:  IsBranch = TRUE;
61
//`CHK:   IsBranch = TRUE;
62
//default:    IsBranch = FALSE;
63
//endcase
64
//endfunction
65
 
66
wire [10:0] brdisp = instr[31:21];
67
 
68
wire iAlu;
69
mIsALU uialu1
70
(
71
        .instr(instr),
72
        .IsALU(iAlu)
73
);
74
 
75
function IsTLB;
76
input [47:0] isn;
77
case(isn[`INSTRUCTION_OP])
78
`R2:
79
  case(isn[`INSTRUCTION_S2])
80
  `TLB:   IsTLB = TRUE;
81
  default:    IsTLB = FALSE;
82
  endcase
83
default:    IsTLB = FALSE;
84
endcase
85
endfunction
86
 
87
reg IsALU;
88
always @*
89
case(instr[`INSTRUCTION_OP])
90
`R2:
91
        if (instr[`INSTRUCTION_L2]==2'b00)
92
                case(instr[`INSTRUCTION_S2])
93
                `VMOV:          IsALU = TRUE;
94
    `RTI:       IsALU = FALSE;
95
    default:    IsALU = TRUE;
96
    endcase
97
  else
98
        IsALU = TRUE;
99
`BRK:   IsALU = FALSE;
100
`Bcc:   IsALU = FALSE;
101 61 robfinch
`BLcc:  IsALU = FALSE;
102 60 robfinch
`BBc:   IsALU = FALSE;
103
`BEQI:  IsALU = FALSE;
104 61 robfinch
`BNEI:  IsALU = FALSE;
105 60 robfinch
`CHK:   IsALU = FALSE;
106
`JAL:   IsALU = FALSE;
107
`JMP:   IsALU = FALSE;
108
`CALL:  IsALU = FALSE;
109
`RET:   IsALU = FALSE;
110
`FVECTOR:
111
        case(instr[`INSTRUCTION_S2])
112
  `VSHL,`VSHR,`VASR:  IsALU = TRUE;
113
  default:    IsALU = FALSE;  // Integer
114
  endcase
115
`IVECTOR:
116
        case(instr[`INSTRUCTION_S2])
117
  `VSHL,`VSHR,`VASR:  IsALU = TRUE;
118
  default:    IsALU = TRUE;  // Integer
119
  endcase
120
`FLOAT:         IsALU = FALSE;
121
default:    IsALU = TRUE;
122
endcase
123
 
124
function IsAlu0Only;
125
input [47:0] isn;
126
begin
127
case(isn[`INSTRUCTION_OP])
128
`R2:
129
        if (isn[`INSTRUCTION_L2]==2'b00)
130
                case(isn[`INSTRUCTION_S2])
131
                `TLB:                           IsAlu0Only = TRUE;
132
                `R1:        IsAlu0Only = TRUE;
133
                `SHIFTR,`SHIFT31,`SHIFT63:
134
                        IsAlu0Only = !(instr[25:23]==`SHL || instr[25:23]==`ASL);
135
                `MULU,`MULSU,`MUL,
136
                `MULUH,`MULSUH,`MULH,
137
                `MODU,`MODSU,`MOD: IsAlu0Only = TRUE;
138
                `DIVU,`DIVSU,`DIV: IsAlu0Only = TRUE;
139
                `MIN,`MAX:  IsAlu0Only = TRUE;
140
                default:    IsAlu0Only = FALSE;
141
                endcase
142
        else
143
                IsAlu0Only = FALSE;
144
`MEMNDX:        IsAlu0Only = TRUE;
145
`IVECTOR,`FVECTOR:
146
        case(isn[`INSTRUCTION_S2])
147
        `VSHL,`VSHR,`VASR:  IsAlu0Only = TRUE;
148
        default: IsAlu0Only = FALSE;
149
        endcase
150
`BITFIELD:  IsAlu0Only = TRUE;
151
`MULUI,`MULI,
152
`DIVUI,`DIVI,
153
`MODI:   IsAlu0Only = TRUE;
154
`CSRRW: IsAlu0Only = TRUE;
155
default:    IsAlu0Only = FALSE;
156
endcase
157
end
158
endfunction
159
 
160
function IsFPU;
161
input [47:0] isn;
162
begin
163
case(isn[`INSTRUCTION_OP])
164
`FLOAT: IsFPU = TRUE;
165
`FVECTOR:
166
                    case(isn[`INSTRUCTION_S2])
167
            `VSHL,`VSHR,`VASR:  IsFPU = FALSE;
168
            default:    IsFPU = TRUE;
169
            endcase
170
default:    IsFPU = FALSE;
171
endcase
172
end
173
endfunction
174
 
175
reg IsFlowCtrl;
176
always @*
177
case(instr[`INSTRUCTION_OP])
178
`BRK:    IsFlowCtrl <= TRUE;
179
`R2:    case(instr[`INSTRUCTION_S2])
180
        `RTI:   IsFlowCtrl <= TRUE;
181
        default:    IsFlowCtrl <= FALSE;
182
        endcase
183
`Bcc:   IsFlowCtrl <= TRUE;
184 61 robfinch
`BLcc:  IsFlowCtrl <= TRUE;
185 60 robfinch
`BBc:           IsFlowCtrl <= TRUE;
186
`BEQI:  IsFlowCtrl <= TRUE;
187 61 robfinch
`BNEI:  IsFlowCtrl <= TRUE;
188 60 robfinch
`CHK:   IsFlowCtrl <= TRUE;
189
`JAL:   IsFlowCtrl <= TRUE;
190
`JMP:           IsFlowCtrl <= TRUE;
191
`CALL:  IsFlowCtrl <= TRUE;
192
`RET:   IsFlowCtrl <= TRUE;
193
default:    IsFlowCtrl <= FALSE;
194
endcase
195
 
196
//function IsFlowCtrl;
197
//input [47:0] isn;
198
//begin
199
//case(isn[`INSTRUCTION_OP])
200
//`BRK:    IsFlowCtrl = TRUE;
201
//`RR:    case(isn[`INSTRUCTION_S2])
202
//        `RTI:   IsFlowCtrl = TRUE;
203
//        default:    IsFlowCtrl = FALSE;
204
//        endcase
205
//`Bcc:   IsFlowCtrl = TRUE;
206
//`BBc:         IsFlowCtrl = TRUE;
207
//`BEQI:  IsFlowCtrl = TRUE;
208
//`CHK:   IsFlowCtrl = TRUE;
209
//`JAL:   IsFlowCtrl = TRUE;
210
//`JMP:         IsFlowCtrl = TRUE;
211
//`CALL:  IsFlowCtrl = TRUE;
212
//`RET:   IsFlowCtrl = TRUE;
213
//default:    IsFlowCtrl = FALSE;
214
//endcase
215
//end
216
//endfunction
217
 
218
// fnCanException
219
//
220
// Used by memory issue logic (stores).
221
// Returns TRUE if the instruction can cause an exception.
222
// In debug mode any instruction could potentially cause a breakpoint exception.
223
// Rather than check all the addresses for potential debug exceptions it's
224
// simpler to just have it so that all instructions could exception. This will
225
// slow processing down somewhat as stores will only be done at the head of the
226
// instruction queue, but it's debug mode so we probably don't care.
227
//
228
function fnCanException;
229
input [47:0] isn;
230
begin
231
// ToDo add debug_on as input
232
`ifdef SUPPORT_DBG
233
if (debug_on)
234
    fnCanException = `TRUE;
235
else
236
`endif
237
case(isn[`INSTRUCTION_OP])
238
`FLOAT:
239
    case(isn[`INSTRUCTION_S2])
240
    `FDIV,`FMUL,`FADD,`FSUB,`FTX:
241
        fnCanException = `TRUE;
242
    default:    fnCanException = `FALSE;
243
    endcase
244
`DIVI,`MODI,`MULI:
245
    fnCanException = `TRUE;
246
`R2:
247
    case(isn[`INSTRUCTION_S2])
248
    `MUL,
249
    `DIV,`MULSU,`DIVSU,
250
    `MOD,`MODSU:
251
       fnCanException = TRUE;
252
    `RTI:   fnCanException = TRUE;
253
    default:    fnCanException = FALSE;
254
    endcase
255
// Had branches that could exception if looping to self. But in a tight loop
256
// it affects store performance.
257
// -> A branch may only exception if it loops back to itself.
258 61 robfinch
`Bcc,`BLcc,`BBc,`BEQI,`BNEI:    fnCanException = isn[7] ? brdisp == 11'h7FF : brdisp == 11'h7FE;
259 60 robfinch
`CHK:   fnCanException = TRUE;
260
default:
261
// Stores can stil exception if there is a write buffer, but we allow following
262
// stores to be issued by ignoring the fact they can exception because the stores
263
// can be undone by invalidating the write buffer.
264
`ifdef HAS_WB
265 61 robfinch
    fnCanException = IsMem && !IsStore(isn);
266 60 robfinch
`else
267 61 robfinch
    fnCanException = IsMem;
268 60 robfinch
`endif
269
endcase
270
end
271
endfunction
272
 
273
function IsLoad;
274
input [47:0] isn;
275
case(isn[`INSTRUCTION_OP])
276
`MEMNDX:        IsLoad = !isn[31];
277
`LB:    IsLoad = TRUE;
278
`LBU:   IsLoad = TRUE;
279
`Lx:    IsLoad = TRUE;
280
`LxU:   IsLoad = TRUE;
281
`LWR:   IsLoad = TRUE;
282
`LV:    IsLoad = TRUE;
283
`LVx:   IsLoad = TRUE;
284
`LVxU:  IsLoad = TRUE;
285
default:    IsLoad = FALSE;
286
endcase
287
endfunction
288
 
289 61 robfinch
function IsMov2Seg;
290
input [47:0] isn;
291
case(isn[`INSTRUCTION_OP])
292
`R2:
293
        if (isn[6])
294
                IsMov2Seg = isn[47:42]==`MOV2SEG;
295
        else
296
    case(isn[`INSTRUCTION_S2])
297
                `MOV2SEG:       IsMov2Seg = TRUE;
298
                `RTI:                   IsMov2Seg = TRUE;
299
                default:        IsMov2Seg = FALSE;
300
                endcase
301
`RET:
302
        IsMov2Seg = TRUE;
303
default:        IsMov2Seg = FALSE;
304
endcase
305
endfunction
306
 
307 60 robfinch
function IsVolatileLoad;
308
input [47:0] isn;
309
case(isn[`INSTRUCTION_OP])
310 61 robfinch
`R2:
311
        if (isn[6])
312
                IsVolatileLoad = isn[47:42]==`MOV2SEG;
313
        else
314
                IsVolatileLoad = isn[31:26]==`MOV2SEG;
315 60 robfinch
`MEMNDX:
316
        if (isn[`INSTRUCTION_L2]==2'b00)
317
    case({isn[31:28],isn[22:21]})
318
    `LWRX:      IsVolatileLoad = TRUE;
319
    `LVBX:      IsVolatileLoad = TRUE;
320
    `LVBUX:     IsVolatileLoad = TRUE;
321
    `LVCX:      IsVolatileLoad = TRUE;
322
    `LVCUX:     IsVolatileLoad = TRUE;
323
    `LVHX:      IsVolatileLoad = TRUE;
324
    `LVHUX:     IsVolatileLoad = TRUE;
325
    `LVWX:      IsVolatileLoad = TRUE;
326
    default: IsVolatileLoad = FALSE;
327
    endcase
328
        else
329
                IsVolatileLoad = FALSE;
330
`LWR:   IsVolatileLoad = TRUE;
331
`LVx:   IsVolatileLoad = TRUE;
332
`LVxU:  IsVolatileLoad = TRUE;
333
default:    IsVolatileLoad = FALSE;
334
endcase
335
endfunction
336
 
337
function IsStore;
338
input [47:0] isn;
339
case(isn[`INSTRUCTION_OP])
340
`MEMNDX:
341
        if (isn[`INSTRUCTION_L2]==2'b10) begin
342
                if (isn[31])
343
                        case({isn[31:28],isn[17:16]})
344
                        `PUSH:  IsStore = TRUE;
345
            default:    IsStore = FALSE;
346
                        endcase
347
                else
348
                        IsStore = FALSE;
349
        end
350
        else if (isn[`INSTRUCTION_L2]==2'b00)
351
                case({isn[31:28],isn[17:16]})
352
                `PUSH:  IsStore = TRUE;
353
    `SBX:   IsStore = TRUE;
354
    `SCX:   IsStore = TRUE;
355
    `SHX:   IsStore = TRUE;
356
    `SWX:   IsStore = TRUE;
357
    `SWCX:  IsStore = TRUE;
358
    `SVX:   IsStore = TRUE;
359
    `CASX:  IsStore = TRUE;
360
    `INC:       IsStore = TRUE;
361
    default:    IsStore = FALSE;
362
    endcase
363
        else
364
                IsStore = FALSE;
365 61 robfinch
`PUSHC: IsStore = TRUE;
366 60 robfinch
`SB:    IsStore = TRUE;
367
`Sx:    IsStore = TRUE;
368
`SWC:   IsStore = TRUE;
369
`INC:   IsStore = TRUE;
370
`SV:    IsStore = TRUE;
371
`CAS:   IsStore = TRUE;
372
`AMO:   IsStore = TRUE;
373
default:    IsStore = FALSE;
374
endcase
375
endfunction
376
 
377
function IsPush;
378
input [47:0] isn;
379
case(isn[`INSTRUCTION_OP])
380
`MEMNDX:
381
        if (isn[`INSTRUCTION_L2]==2'b10) begin
382
                if (isn[31])
383
                        case({isn[31:28],isn[17:16]})
384
                        `PUSH:  IsPush = TRUE;
385
            default:    IsPush = FALSE;
386
                        endcase
387
                else
388
                        IsPush = FALSE;
389
        end
390
        else if (isn[`INSTRUCTION_L2]==2'b00)
391
                case({isn[31:28],isn[17:16]})
392
                `PUSH:  IsPush = TRUE;
393
    default:    IsPush = FALSE;
394
    endcase
395
        else
396
                IsPush = FALSE;
397 61 robfinch
`PUSHC: IsPush = TRUE;
398 60 robfinch
default:    IsPush = FALSE;
399
endcase
400
endfunction
401
 
402 61 robfinch
function IsPushc;
403 60 robfinch
input [47:0] isn;
404
case(isn[`INSTRUCTION_OP])
405 61 robfinch
`PUSHC: IsPushc = TRUE;
406
default:    IsPushc = FALSE;
407
endcase
408
endfunction
409
 
410
//function [0:0] IsMem;
411
reg IsMem;
412
always @*
413
//input [47:0] isn;
414
case(instr[`INSTRUCTION_OP])
415
`R2:
416
        if (instr[6])
417
                IsMem = instr[47:42]==`MOV2SEG;
418
        else
419
    case(instr[`INSTRUCTION_S2])
420
                `MOV2SEG:       IsMem = TRUE;
421
                `RTI:                   IsMem = TRUE;
422
                default:        IsMem = FALSE;
423
                endcase
424 60 robfinch
`MEMNDX:        IsMem = TRUE;
425
`AMO:           IsMem = TRUE;
426
`LB:    IsMem = TRUE;
427
`LBU:   IsMem = TRUE;
428
`Lx:    IsMem = TRUE;
429
`LxU:   IsMem = TRUE;
430
`LWR:   IsMem = TRUE;
431
`LV,`SV:    IsMem = TRUE;
432
`INC:           IsMem = TRUE;
433 61 robfinch
`PUSHC: IsMem = TRUE;
434 60 robfinch
`SB:    IsMem = TRUE;
435
`Sx:    IsMem = TRUE;
436
`SWC:   IsMem = TRUE;
437
`CAS:   IsMem = TRUE;
438
`LVx:           IsMem = TRUE;
439
`LVxU:  IsMem = TRUE;
440 61 robfinch
//`RET:         IsMem = TRUE;???
441 60 robfinch
default:    IsMem = FALSE;
442
endcase
443 61 robfinch
//endfunction
444 60 robfinch
 
445
function IsMemNdx;
446
input [47:0] isn;
447
case(isn[`INSTRUCTION_OP])
448
`MEMNDX:        IsMemNdx = TRUE;
449
default:    IsMemNdx = FALSE;
450
endcase
451
endfunction
452
 
453
function [2:0] MemSize;
454
input [47:0] isn;
455
case(isn[`INSTRUCTION_OP])
456
`MEMNDX:
457
        if (isn[`INSTRUCTION_L2]==2'b00) begin
458
                if (IsLoad(isn))
459
            case({isn[31:28],isn[22:21]})
460
            `LVBX,`LVBUX:       MemSize = byt;
461
            `LBX,`LBUX:   MemSize = byt;
462
            `LVCX,`LVCUX:                        MemSize = wyde;
463
            `LCX,`LCUX:   MemSize = wyde;
464
            `LVHX,`LVHUX:               MemSize = tetra;
465
            `LHX:   MemSize = tetra;
466
            `LHUX: MemSize = tetra;
467
            `LVWX:                       MemSize = octa;
468
            `LWX:   MemSize = octa;
469
            `LWRX: MemSize = octa;
470
            `LVX:   MemSize = octa;
471
            `LVx:
472
                case(isn[20:18])
473
                3'd0,3'd1:      MemSize = byt;
474
                3'd2,3'd3:      MemSize = wyde;
475
                3'd4,3'd5:      MemSize = tetra;
476
                default:        MemSize = octa;
477
                endcase
478
            default: MemSize = octa;
479
                endcase
480
          else
481
                        case({isn[31:28],isn[17:16]})
482
            `SBX:   MemSize = byt;
483
            `SCX:   MemSize = wyde;
484
            `SHX:   MemSize = tetra;
485
            `SWX:   MemSize = octa;
486
            `SWCX: MemSize = octa;
487
            `SVX:   MemSize = octa;
488
            default: MemSize = octa;
489
                        endcase
490
  end
491
        else
492
                MemSize = octa;
493
`LB,`LBU:    MemSize = byt;
494
`Lx,`LxU,`LVx,`LVxU:
495 61 robfinch
        casez(isn[21:18])
496
        4'b1000:        MemSize = hexi;
497
        4'b?100:        MemSize = octa;
498
        4'b??10:        MemSize = tetra;
499
        4'b???1:        MemSize = wyde;
500 60 robfinch
        default:        MemSize = octa;
501
        endcase
502
`LWR:  MemSize = octa;
503
`LV:    MemSize = octa;
504
`AMO:
505
        case(isn[23:21])
506
        3'd0:   MemSize = byt;
507
        3'd1:   MemSize = wyde;
508
        3'd2:   MemSize = tetra;
509
        3'd3:   MemSize = octa;
510
        default:        MemSize = octa;
511
        endcase
512
`SB:    MemSize = byt;
513
`Sx:
514 61 robfinch
        casez(isn[16:13])
515
        4'b1000:        MemSize = hexi;
516
        4'b?100:        MemSize = octa;
517
        4'b??10:        MemSize = tetra;
518
        4'b???1:        MemSize = wyde;
519 60 robfinch
        default:        MemSize = octa;
520
        endcase
521
`SWC:  MemSize = octa;
522
`SV:    MemSize = octa;
523 61 robfinch
`PUSHC: MemSize = octa;
524 60 robfinch
default:    MemSize = octa;
525
endcase
526
endfunction
527
 
528
function IsCAS;
529
input [47:0] isn;
530
case(isn[`INSTRUCTION_OP])
531
`MEMNDX:
532
        if (isn[`INSTRUCTION_L2]==2'b00)
533
                case({isn[31:28],isn[17:16]})
534
    `CASX:   IsCAS = TRUE;
535
    default:    IsCAS = FALSE;
536
    endcase
537
        else
538
                IsCAS = FALSE;
539
`CAS:       IsCAS = TRUE;
540
default:    IsCAS = FALSE;
541
endcase
542
endfunction
543
 
544
function IsAMO;
545
input [47:0] isn;
546
case(isn[`INSTRUCTION_OP])
547
`AMO:       IsAMO = TRUE;
548
default:    IsAMO = FALSE;
549
endcase
550
endfunction
551
 
552
function IsInc;
553
input [47:0] isn;
554
case(isn[`INSTRUCTION_OP])
555
`MEMNDX:
556
        if (isn[`INSTRUCTION_L2]==2'b00)
557
                case({isn[31:28],isn[17:16]})
558
    `INCX:   IsInc = TRUE;
559
    default:    IsInc = FALSE;
560
    endcase
561
        else
562
                IsInc = FALSE;
563
`INC:    IsInc = TRUE;
564
default:    IsInc = FALSE;
565
endcase
566
endfunction
567
 
568
function IsFSync;
569
input [47:0] isn;
570
IsFSync = (isn[`INSTRUCTION_OP]==`FLOAT && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`FSYNC);
571
endfunction
572
 
573
function IsMemdb;
574
input [47:0] isn;
575
IsMemdb = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMDB);
576
endfunction
577
 
578
function IsMemsb;
579
input [47:0] isn;
580
IsMemsb = (isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMSB);
581
endfunction
582
 
583
function IsSEI;
584
input [47:0] isn;
585
IsSEI = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`SEI);
586
endfunction
587
 
588
function IsShift48;
589
input [47:0] isn;
590
case(isn[`INSTRUCTION_OP])
591
`R2:
592
        if (isn[`INSTRUCTION_L2]==2'b01)
593
    case(isn[47:42])
594
    `SHIFTR: IsShift48 = TRUE;
595
    default: IsShift48 = FALSE;
596
    endcase
597
  else
598
        IsShift48 = FALSE;
599
default: IsShift48 = FALSE;
600
endcase
601
endfunction
602
 
603
function IsShift;
604
input [47:0] isn;
605
case(isn[`INSTRUCTION_OP])
606
`R2:
607
        if (isn[`INSTRUCTION_L2]==2'b00)
608
    case(isn[31:26])
609
    `SHIFTR: IsShift = TRUE;
610
    `SHIFT31: IsShift = TRUE;
611
    `SHIFT63: IsShift = TRUE;
612
    default: IsShift = FALSE;
613
    endcase
614
  else
615
        IsShift = FALSE;
616
default: IsShift = FALSE;
617
endcase
618
endfunction
619
 
620
function IsLWRX;
621
input [47:0] isn;
622
case(isn[`INSTRUCTION_OP])
623
`MEMNDX:
624
        if (isn[`INSTRUCTION_L2]==2'b00)
625
    case({isn[31:28],isn[22:21]})
626
    `LWRX:   IsLWRX = TRUE;
627
    default:    IsLWRX = FALSE;
628
    endcase
629
        else
630
                IsLWRX = FALSE;
631
default:    IsLWRX = FALSE;
632
endcase
633
endfunction
634
 
635
// Aquire / release bits are only available on indexed SWC / LWR
636
function IsSWCX;
637
input [47:0] isn;
638
case(isn[`INSTRUCTION_OP])
639
`MEMNDX:
640
        if (isn[`INSTRUCTION_L2]==2'b00)
641
                case({isn[31:28],isn[17:16]})
642
    `SWCX:   IsSWCX = TRUE;
643
    default:    IsSWCX = FALSE;
644
    endcase
645
        else
646
                IsSWCX = FALSE;
647
default:    IsSWCX = FALSE;
648
endcase
649
endfunction
650
 
651
function IsJmp;
652
input [47:0] isn;
653
IsJmp = isn[`INSTRUCTION_OP]==`JMP;
654
endfunction
655
 
656
// Really IsPredictableBranch
657
// Does not include BccR's
658
function IsBranch;
659
input [47:0] isn;
660
casez(isn[`INSTRUCTION_OP])
661
`Bcc:   IsBranch = TRUE;
662 61 robfinch
`BLcc:  IsBranch = TRUE;
663 60 robfinch
`BBc:   IsBranch = TRUE;
664
`BEQI:  IsBranch = TRUE;
665 61 robfinch
`BNEI:  IsBranch = TRUE;
666 60 robfinch
`CHK:   IsBranch = TRUE;
667
default:    IsBranch = FALSE;
668
endcase
669
endfunction
670
 
671
function IsJAL;
672
input [47:0] isn;
673
IsJAL = isn[`INSTRUCTION_OP]==`JAL;
674
endfunction
675
 
676
function IsRet;
677
input [47:0] isn;
678
IsRet = isn[`INSTRUCTION_OP]==`RET;
679
endfunction
680
 
681
function IsIrq;
682
input [47:0] isn;
683
IsIrq = isn[`INSTRUCTION_OP]==`BRK && isn[25:21]==5'h0;
684
endfunction
685
 
686
function IsBrk;
687
input [47:0] isn;
688
IsBrk = isn[`INSTRUCTION_OP]==`BRK;
689
endfunction
690
 
691
function IsRti;
692
input [47:0] isn;
693
IsRti = isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_S2]==`RTI;
694
endfunction
695
 
696
function IsSync;
697
input [47:0] isn;
698 61 robfinch
IsSync = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`SYNC) || IsRti(isn) || IsMov2Seg(isn);
699 60 robfinch
endfunction
700
 
701
// Has an extendable 14-bit constant
702
function HasConst;
703
input [47:0] isn;
704
casez(isn[`INSTRUCTION_OP])
705
`ADDI:  HasConst = TRUE;
706 61 robfinch
`SEQI:  HasConst = TRUE;
707 60 robfinch
`SLTI:  HasConst = TRUE;
708
`SLTUI: HasConst = TRUE;
709
`SGTI:  HasConst = TRUE;
710
`SGTUI: HasConst = TRUE;
711
`ANDI:  HasConst = TRUE;
712
`ORI:   HasConst = TRUE;
713
`XORI:  HasConst = TRUE;
714
`XNORI: HasConst = TRUE;
715
`MULUI: HasConst = TRUE;
716
`MULI:  HasConst = TRUE;
717
`MULFI: HasConst = TRUE;
718
`DIVUI: HasConst = TRUE;
719
`DIVI:  HasConst = TRUE;
720
`MODI:  HasConst = TRUE;
721
`LB:    HasConst = TRUE;
722
`LBU:   HasConst = TRUE;
723
`Lx:    HasConst = TRUE;
724
`LxU:   HasConst = TRUE;
725
`LWR:           HasConst = TRUE;
726
`LV:    HasConst = TRUE;
727
`SB:    HasConst = TRUE;
728
`Sx:    HasConst = TRUE;
729
`SWC:   HasConst = TRUE;
730
`INC:           HasConst = TRUE;
731
`SV:    HasConst = TRUE;
732
`CAS:   HasConst = TRUE;
733
`JAL:   HasConst = TRUE;
734
`CALL:  HasConst = TRUE;
735
`RET:   HasConst = TRUE;
736
`LVx:           HasConst = TRUE;
737
`LVxU:  HasConst = TRUE;
738 61 robfinch
`PUSHC: HasConst = TRUE;
739 60 robfinch
default:    HasConst = FALSE;
740
endcase
741
endfunction
742
 
743
function IsOddball;
744
input [47:0] instr;
745
//if (|iqentry_exc[head])
746
//    IsOddball = TRUE;
747
//else
748
case(instr[`INSTRUCTION_OP])
749
`BRK:   IsOddball = TRUE;
750
`IVECTOR:
751
    case(instr[`INSTRUCTION_S2])
752
    `VSxx:  IsOddball = TRUE;
753
    default:    IsOddball = FALSE;
754
    endcase
755
`RR:
756
    case(instr[`INSTRUCTION_S2])
757
    `VMOV:  IsOddball = TRUE;
758
    `SEI,`RTI: IsOddball = TRUE;
759
    default:    IsOddball = FALSE;
760
    endcase
761
`MEMNDX:
762
                case({instr[31:28],instr[17:16]})
763
    `CACHEX:  IsOddball = TRUE;
764
    default:    IsOddball = FALSE;
765
    endcase
766
`CSRRW,`REX,`CACHE,`FLOAT:  IsOddball = TRUE;
767
default:    IsOddball = FALSE;
768
endcase
769
endfunction
770
 
771
function IsRFW;
772
input [47:0] isn;
773
casez(isn[`INSTRUCTION_OP])
774
`IVECTOR:   IsRFW = TRUE;
775
`FVECTOR:   IsRFW = TRUE;
776
`R2:
777
        if (isn[`INSTRUCTION_L2]==2'b00)
778
    casez(isn[`INSTRUCTION_S2])
779
    `TLB:               IsRFW = TRUE;
780
    `R1:
781
                case(isn[22:18])
782
                `MEMDB,`MEMSB,`SYNC,`SETWB,5'h14,5'h15: IsRFW = FALSE;
783
                default:        IsRFW = TRUE;
784
                endcase
785
    `ADD:   IsRFW = TRUE;
786
    `SUB:   IsRFW = TRUE;
787 61 robfinch
    `SEQ:   IsRFW = TRUE;
788 60 robfinch
    `SLT:   IsRFW = TRUE;
789
    `SLTU:  IsRFW = TRUE;
790
    `SLE:   IsRFW = TRUE;
791
    `SLEU:  IsRFW = TRUE;
792
    `AND:   IsRFW = TRUE;
793
    `OR:    IsRFW = TRUE;
794
    `XOR:   IsRFW = TRUE;
795
    `NAND:      IsRFW = TRUE;
796
    `NOR:               IsRFW = TRUE;
797
    `XNOR:      IsRFW = TRUE;
798
    `MULU:  IsRFW = TRUE;
799
    `MULSU: IsRFW = TRUE;
800
    `MUL:   IsRFW = TRUE;
801
    `MULUH:  IsRFW = TRUE;
802
    `MULSUH: IsRFW = TRUE;
803
    `MULH:   IsRFW = TRUE;
804
    `MULF:      IsRFW = TRUE;
805
    `FXMUL:     IsRFW = TRUE;
806
    `DIVU:  IsRFW = TRUE;
807
    `DIVSU: IsRFW = TRUE;
808
    `DIV:IsRFW = TRUE;
809
    `MODU:  IsRFW = TRUE;
810
    `MODSU: IsRFW = TRUE;
811
    `MOD:IsRFW = TRUE;
812
    `MOV:       IsRFW = TRUE;
813
    `VMOV:      IsRFW = TRUE;
814
    `SHIFTR,`SHIFT31,`SHIFT63:
815
                IsRFW = TRUE;
816
    `MIN,`MAX:    IsRFW = TRUE;
817
    `SEI:       IsRFW = TRUE;
818
    default:    IsRFW = FALSE;
819
    endcase
820
        else if (isn[`INSTRUCTION_L2]==2'b01)
821
                case(isn[47:42])
822
                `CMOVEZ:        IsRFW = TRUE;
823
                `CMOVNZ:        IsRFW = TRUE;
824
                default:        IsRFW = FALSE;
825
                endcase
826
        else if (isn[7]==1'b1)
827
    casez(isn[`INSTRUCTION_S2])
828
    `ADD:   IsRFW = TRUE;
829
    `SUB:   IsRFW = TRUE;
830
    `AND:   IsRFW = TRUE;
831
    `OR:    IsRFW = TRUE;
832
    `XOR:   IsRFW = TRUE;
833
    `MOV:       IsRFW = TRUE;
834
    `SHIFTR,`SHIFT31,`SHIFT63:
835
                IsRFW = TRUE;
836
    default:    IsRFW = FALSE;
837
    endcase
838
        else
839
                IsRFW = FALSE;
840
`MEMNDX:
841
        if (isn[`INSTRUCTION_L2]==2'b10) begin
842
                if (IsLoad(isn))
843
                        IsRFW = TRUE;
844
                else
845
                        case({isn[31:28],isn[17:16]})
846
                        `PUSH:  IsRFW = TRUE;
847
            `CASX:  IsRFW = TRUE;
848
            default:    IsRFW = FALSE;
849
            endcase
850
        end
851
        else if (isn[`INSTRUCTION_L2]==2'b00) begin
852
                if (IsLoad(isn))
853
            case({isn[31:28],isn[22:21]})
854
            `LBX:   IsRFW = TRUE;
855
            `LBUX:  IsRFW = TRUE;
856
            `LCX:   IsRFW = TRUE;
857
            `LCUX:  IsRFW = TRUE;
858
            `LHX:   IsRFW = TRUE;
859
            `LHUX:  IsRFW = TRUE;
860
            `LWX:   IsRFW = TRUE;
861
            `LVBX:  IsRFW = TRUE;
862
            `LVBUX: IsRFW = TRUE;
863
            `LVCX:  IsRFW = TRUE;
864
            `LVCUX: IsRFW = TRUE;
865
            `LVHX:  IsRFW = TRUE;
866
            `LVHUX: IsRFW = TRUE;
867
            `LVWX:  IsRFW = TRUE;
868
            `LWX:   IsRFW = TRUE;
869
            `LWRX:  IsRFW = TRUE;
870
            `LVX:   IsRFW = TRUE;
871
            default:    IsRFW = FALSE;
872
                endcase
873
          else
874
                        case({isn[31:28],isn[17:16]})
875
                        `PUSH:  IsRFW = TRUE;
876
            `CASX:  IsRFW = TRUE;
877
            default:    IsRFW = FALSE;
878
            endcase
879
  end
880
        else
881
                IsRFW = FALSE;
882
`BBc:   IsRFW = FALSE;
883
`BITFIELD:  IsRFW = TRUE;
884
`ADDI:      IsRFW = TRUE;
885 61 robfinch
`SEQI:      IsRFW = TRUE;
886 60 robfinch
`SLTI:      IsRFW = TRUE;
887
`SLTUI:     IsRFW = TRUE;
888
`SGTI:      IsRFW = TRUE;
889
`SGTUI:     IsRFW = TRUE;
890
`ANDI:      IsRFW = TRUE;
891
`ORI:       IsRFW = TRUE;
892
`XORI:      IsRFW = TRUE;
893
`XNORI:     IsRFW = TRUE;
894
`MULUI:     IsRFW = TRUE;
895
`MULI:      IsRFW = TRUE;
896
`MULFI:                 IsRFW = TRUE;
897
`DIVUI:     IsRFW = TRUE;
898
`DIVI:      IsRFW = TRUE;
899
`MODI:      IsRFW = TRUE;
900
`JAL:       IsRFW = TRUE;
901
`CALL:      IsRFW = TRUE;
902
`RET:       IsRFW = TRUE;
903
`LB:        IsRFW = TRUE;
904
`LBU:       IsRFW = TRUE;
905
`Lx:        IsRFW = TRUE;
906
`LxU:       IsRFW = TRUE;
907
`LWR:       IsRFW = TRUE;
908
`LV:        IsRFW = TRUE;
909
`LVx:                           IsRFW = TRUE;
910
`LVxU:                  IsRFW = TRUE;
911 61 robfinch
`PUSHC:                 IsRFW = TRUE;
912 60 robfinch
`CAS:       IsRFW = TRUE;
913
`AMO:                           IsRFW = TRUE;
914
`CSRRW:                 IsRFW = TRUE;
915
`AUIPC:                 IsRFW = TRUE;
916
`LUI:                           IsRFW = TRUE;
917
default:    IsRFW = FALSE;
918
endcase
919
endfunction
920
 
921
// Determines which lanes of the target register get updated.
922
function [7:0] fnWe;
923
input [47:0] isn;
924
casez(isn[`INSTRUCTION_OP])
925
`R2:
926
        case(isn[`INSTRUCTION_S2])
927
        `CMP:   fnWe = 8'h00;                   // CMP sets predicate registers so doesn't update general register file.
928
        default: fnWe = 8'hFF;
929
        endcase
930
default: fnWe = 8'hFF;
931
endcase
932
/*
933
casez(isn[`INSTRUCTION_OP])
934
`R2:
935
        case(isn[`INSTRUCTION_S2])
936
        `R1:
937
                case(isn[22:18])
938
                `ABS,`CNTLZ,`CNTLO,`CNTPOP:
939
                        case(isn[25:23])
940
                        3'b000: fnWe = 8'h01;
941
                        3'b001: fnWe = 8'h03;
942
                        3'b010: fnWe = 8'h0F;
943
                        3'b011: fnWe = 8'hFF;
944
                        default:        fnWe = 8'hFF;
945
                        endcase
946
                default: fnWe = 8'hFF;
947
                endcase
948
        `SHIFT31:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
949
        `SHIFT63:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
950
        `SLT,`SLTU,`SLE,`SLEU,
951
        `ADD,`SUB,
952
        `AND,`OR,`XOR,
953
        `NAND,`NOR,`XNOR,
954
        `DIV,`DIVU,`DIVSU,
955
        `MOD,`MODU,`MODSU,
956
        `MUL,`MULU,`MULSU,
957
        `MULH,`MULUH,`MULSUH,
958
        `FXMUL:
959
                case(isn[25:23])
960
                3'b000: fnWe = 8'h01;
961
                3'b001: fnWe = 8'h03;
962
                3'b010: fnWe = 8'h0F;
963
                3'b011: fnWe = 8'hFF;
964
                default:        fnWe = 8'hFF;
965
                endcase
966
        default: fnWe = 8'hFF;
967
        endcase
968
default:        fnWe = 8'hFF;
969
endcase
970
*/
971
endfunction
972
 
973
// Detect if a source is automatically valid
974
function Source1Valid;
975
input [47:0] isn;
976
casez(isn[`INSTRUCTION_OP])
977
`BRK:   Source1Valid = TRUE;
978
`Bcc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
979 61 robfinch
`BLcc:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
980 60 robfinch
`BBc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
981
`BEQI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
982 61 robfinch
`BNEI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
983 60 robfinch
`CHK:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
984
`R2:    case(isn[`INSTRUCTION_S2])
985
        `SHIFT31:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
986
        `SHIFT63:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
987
        `SHIFTR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
988
        default:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
989
        endcase
990
`MEMNDX:        Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
991
`ADDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
992 61 robfinch
`SEQI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
993 60 robfinch
`SLTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
994
`SLTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
995
`SGTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
996
`SGTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
997
`ANDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
998
`ORI:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
999
`XORI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1000
`XNORI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1001
`MULUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1002
`AMO:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1003
`LB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1004
`LBU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1005
`Lx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1006
`LxU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1007
`LWR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1008
`LV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1009
`LVx:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1010
`SB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1011
`Sx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1012
`SWC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1013
`SV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1014 61 robfinch
`PUSHC: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1015 60 robfinch
`INC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1016
`CAS:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1017
`JAL:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1018
`RET:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1019
`CSRRW: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1020
`BITFIELD:      case(isn[31:28])
1021
                        `BFINSI:        Source1Valid = TRUE;
1022
                        default:        Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1023
                        endcase
1024
`IVECTOR:
1025
                        Source1Valid = FALSE;
1026
default:    Source1Valid = TRUE;
1027
endcase
1028
endfunction
1029
 
1030
function Source2Valid;
1031
input [47:0] isn;
1032
casez(isn[`INSTRUCTION_OP])
1033
`BRK:   Source2Valid = TRUE;
1034
`Bcc:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
1035 61 robfinch
`BLcc:  Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
1036 60 robfinch
`BBc:   Source2Valid = TRUE;
1037
`BEQI:  Source2Valid = TRUE;
1038 61 robfinch
`BNEI:  Source2Valid = TRUE;
1039 60 robfinch
`CHK:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
1040
`R2:    case(isn[`INSTRUCTION_S2])
1041
        `R1:       Source2Valid = TRUE;
1042 61 robfinch
        `SHIFT31:  Source2Valid = TRUE;
1043
        `SHIFT63:  Source2Valid = TRUE;
1044 60 robfinch
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
1045
        endcase
1046
`MEMNDX:
1047
                                if (IsLoad(isn))
1048
                                        case({isn[31:28],isn[22:21]})
1049
                `LVX: Source2Valid = FALSE;
1050
                default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
1051
                endcase
1052
        else
1053
                                        case({isn[31:28],isn[17:16]})
1054
                `SVX: Source2Valid = FALSE;
1055
                default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
1056
                endcase
1057
`ADDI:  Source2Valid = TRUE;
1058 61 robfinch
`SEQI:  Source2Valid = TRUE;
1059 60 robfinch
`SLTI:  Source2Valid = TRUE;
1060
`SLTUI: Source2Valid = TRUE;
1061
`SGTI:  Source2Valid = TRUE;
1062
`SGTUI: Source2Valid = TRUE;
1063
`ANDI:  Source2Valid = TRUE;
1064
`ORI:   Source2Valid = TRUE;
1065
`XORI:  Source2Valid = TRUE;
1066
`XNORI: Source2Valid = TRUE;
1067
`MULUI: Source2Valid = TRUE;
1068
`LB:    Source2Valid = TRUE;
1069
`LBU:   Source2Valid = TRUE;
1070
`Lx:    Source2Valid = TRUE;
1071
`LxU:   Source2Valid = TRUE;
1072
`LWR:   Source2Valid = TRUE;
1073
`LVx:   Source2Valid = TRUE;
1074
`INC:           Source2Valid = TRUE;
1075
`SB:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
1076
`Sx:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
1077
`SWC:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
1078 61 robfinch
`PUSHC: Source2Valid = TRUE;
1079 60 robfinch
`CAS:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
1080
`JAL:   Source2Valid = TRUE;
1081
`RET:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
1082
`IVECTOR:
1083
                    case(isn[`INSTRUCTION_S2])
1084
            `VABS:  Source2Valid = TRUE;
1085
            `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
1086
                Source2Valid = FALSE;
1087
            `VADDS,`VSUBS,`VANDS,`VORS,`VXORS:
1088
                Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
1089
            `VBITS2V:   Source2Valid = TRUE;
1090
            `V2BITS:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
1091
            `VSHL,`VSHR,`VASR:  Source2Valid = isn[22:21]==2'd2;
1092
            default:    Source2Valid = FALSE;
1093
            endcase
1094
`LV:        Source2Valid = TRUE;
1095
`SV:        Source2Valid = FALSE;
1096
`AMO:           Source2Valid = isn[31] || isn[`INSTRUCTION_RB]==5'd0;
1097
default:    Source2Valid = TRUE;
1098
endcase
1099
endfunction
1100
 
1101
function Source3Valid;
1102
input [47:0] isn;
1103
case(isn[`INSTRUCTION_OP])
1104
`IVECTOR:
1105
    case(isn[`INSTRUCTION_S2])
1106
    `VEX:       Source3Valid = TRUE;
1107
    default:    Source3Valid = TRUE;
1108
    endcase
1109
`CHK:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
1110
`R2:
1111
        if (isn[`INSTRUCTION_L2]==2'b01)
1112
                case(isn[47:42])
1113
    `CMOVEZ,`CMOVNZ:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
1114
                default:        Source3Valid = TRUE;
1115
                endcase
1116
        else
1117
    case(isn[`INSTRUCTION_S2])
1118
    `MAJ:               Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
1119
    default:    Source3Valid = TRUE;
1120
    endcase
1121
`MEMNDX:
1122
        if (isn[`INSTRUCTION_L2]==2'b00)
1123
                case({isn[31:28],isn[17:16]})
1124
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
1125
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
1126
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
1127
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
1128
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
1129
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
1130
    default:    Source3Valid = TRUE;
1131
    endcase
1132
  else
1133
        Source3Valid = TRUE;
1134
default:    Source3Valid = TRUE;
1135
endcase
1136
endfunction
1137
 
1138
wire isRet = IsRet(instr);
1139
wire isJal = IsJAL(instr);
1140
wire isBrk = IsBrk(instr);
1141
wire isRti = IsRti(instr);
1142
 
1143
`ifdef REGISTER_DECODE
1144
always @(posedge clk)
1145
`else
1146
always @*
1147
`endif
1148
begin
1149
        bus <= 144'h0;
1150 61 robfinch
        bus[`IB_LOADSEG] <= IsMov2Seg(instr);
1151
        bus[`IB_CMP] <= 1'b0;//IsCmp(instr);
1152
        if (IsStore(instr) & !IsPushc(instr))
1153 60 robfinch
                bus[`IB_CONST] <= instr[6]==1'b1 ? {{34{instr[47]}},instr[47:23],instr[17:13]} :
1154
                                                                                                                                                                {{50{instr[31]}},instr[31:23],instr[17:13]};
1155
        else
1156
                bus[`IB_CONST] <= instr[6]==1'b1 ? {{34{instr[47]}},instr[47:18]} :
1157
                                                                                                                                                                {{50{instr[31]}},instr[31:18]};
1158
`ifdef SUPPORT_DCI
1159
        if (instr[`INSTRUCTION_OP]==`CMPRSSD)
1160
                bus[`IB_LN] <= 3'd2 | pred_on;
1161
        else
1162
`endif
1163
                case(instr[7:6])
1164
                2'b00:  bus[`IB_LN] <= 3'd4 | pred_on;
1165
                2'b01:  bus[`IB_LN] <= 3'd6 | pred_on;
1166
                default: bus[`IB_LN] <= 3'd2 | pred_on;
1167
                endcase
1168
//      bus[`IB_RT]              <= fnRt(instr,ven,vl,thrd) | {thrd,7'b0};
1169
//      bus[`IB_RC]              <= fnRc(instr,ven,thrd) | {thrd,7'b0};
1170
//      bus[`IB_RA]              <= fnRa(instr,ven,vl,thrd) | {thrd,7'b0};
1171
        bus[`IB_IMM]     <= HasConst(instr);
1172
//      bus[`IB_A3V]   <= Source3Valid(instr);
1173
//      bus[`IB_A2V]   <= Source2Valid(instr);
1174
//      bus[`IB_A1V]   <= Source1Valid(instr);
1175
        bus[`IB_TLB]     <= IsTLB(instr);
1176
        bus[`IB_SZ]    <= instr[`INSTRUCTION_OP]==`R2 ? instr[25:23] : 3'd3;    // 3'd3=word size
1177
        bus[`IB_IRQ]     <= IsIrq(instr);
1178
        bus[`IB_BRK]     <= isBrk;
1179
        bus[`IB_RTI]     <= isRti;
1180
        bus[`IB_RET]     <= isRet;
1181
        bus[`IB_JAL]     <= isJal;
1182
        // IB_BT is now used to indicate when to update the branch target buffer.
1183
        // This occurs when one of the instructions with an unknown or calculated
1184
        // target is present.
1185
        bus[`IB_BT]              <= isJal | isRet | isBrk | isRti;
1186
        bus[`IB_ALU]   <= IsALU;
1187
        bus[`IB_ALU0]  <= IsAlu0Only(instr);
1188
        bus[`IB_FPU]   <= IsFPU(instr);
1189
        bus[`IB_FC]              <= IsFlowCtrl;
1190
        bus[`IB_CANEX] <= fnCanException(instr);
1191
        bus[`IB_LOADV] <= IsVolatileLoad(instr);
1192
        bus[`IB_LOAD]    <= IsLoad(instr);
1193
        bus[`IB_PRELOAD] <=   IsLoad(instr) && Rt==5'd0;
1194
        bus[`IB_STORE]  <= IsStore(instr);
1195
        bus[`IB_PUSH]   <= IsPush(instr);
1196
        bus[`IB_ODDBALL] <= IsOddball(instr);
1197
        bus[`IB_MEMSZ]  <= MemSize(instr);
1198 61 robfinch
        bus[`IB_MEM]            <= IsMem;
1199 60 robfinch
        bus[`IB_MEMNDX] <= IsMemNdx(instr);
1200
        bus[`IB_RMW]            <= IsCAS(instr) || IsAMO(instr) || IsInc(instr);
1201
        bus[`IB_MEMDB]  <= IsMemdb(instr);
1202
        bus[`IB_MEMSB]  <= IsMemsb(instr);
1203
        bus[`IB_SHFT]   <= IsShift48(instr);//|IsShift(instr);
1204
        bus[`IB_SEI]            <= IsSEI(instr);
1205
        bus[`IB_AQ]                     <= (IsAMO(instr)|IsLWRX(instr)|IsSWCX(instr)) & instr[25];
1206
        bus[`IB_RL]                     <= (IsAMO(instr)|IsLWRX(instr)|IsSWCX(instr)) & instr[24];
1207
        bus[`IB_JMP]            <= IsJmp(instr);
1208
        bus[`IB_BR]                     <= IsBranch(instr);
1209
        bus[`IB_SYNC]           <= IsSync(instr)||IsBrk(instr)||IsRti(instr);
1210
        bus[`IB_FSYNC]  <= IsFSync(instr);
1211
        bus[`IB_RFW]            <= (Rt==5'd0) ? 1'b0 : IsRFW(instr);// && !IsCmp(instr);
1212 61 robfinch
        bus[`IB_PRFW]   <= 1'b0;//IsCmp(instr);
1213 60 robfinch
        bus[`IB_WE]                     <= fnWe(instr);
1214
        id_o <= id_i;
1215
        idv_o <= idv_i;
1216
end
1217
 
1218
endmodule
1219
 
1220
module mIsALU(instr, IsALU);
1221
input [47:0] instr;
1222
output reg IsALU;
1223
parameter TRUE = 1'b1;
1224
parameter FALSE = 1'b0;
1225
 
1226
always @*
1227
casez(instr[`INSTRUCTION_OP])
1228
`R2:
1229
  if (instr[`INSTRUCTION_L2]==2'b00)
1230
                case(instr[`INSTRUCTION_S2])
1231
                `VMOV:          IsALU = TRUE;
1232
    `RTI:       IsALU = FALSE;
1233
    default:    IsALU = TRUE;
1234
    endcase
1235
    else
1236
        IsALU = TRUE;
1237
`BRK:   IsALU = FALSE;
1238
`Bcc:   IsALU = FALSE;
1239 61 robfinch
`BLcc:  IsALU = FALSE;
1240 60 robfinch
`BBc:   IsALU = FALSE;
1241
`BEQI:  IsALU = FALSE;
1242 61 robfinch
`BNEI:  IsALU = FALSE;
1243 60 robfinch
`CHK:   IsALU = FALSE;
1244
`JAL:   IsALU = FALSE;
1245
`JMP:   IsALU = FALSE;
1246
`CALL:  IsALU = FALSE;
1247
`RET:   IsALU = FALSE;
1248
`FVECTOR:
1249
        case(instr[`INSTRUCTION_S2])
1250
  `VSHL,`VSHR,`VASR:  IsALU = TRUE;
1251
  default:    IsALU = FALSE;  // Integer
1252
  endcase
1253
`IVECTOR:
1254
        case(instr[`INSTRUCTION_S2])
1255
  `VSHL,`VSHR,`VASR:  IsALU = TRUE;
1256
  default:    IsALU = TRUE;  // Integer
1257
  endcase
1258
`FLOAT:         IsALU = FALSE;
1259
default:    IsALU = TRUE;
1260
endcase
1261
 
1262
endmodule

powered by: WebSVN 2.1.0

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