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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [rtl/] [common/] [FT64_idecoder.v] - Blame information for rev 48

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

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2017-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      FT64_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_defines.vh"
26
 
27
module FT64_idecoder(clk,idv_i,id_i,instr,vl,ven,thrd,predict_taken,Rt,bus,id_o,idv_o);
28
input clk;
29
input idv_i;
30
input [4:0] id_i;
31
input [47:0] instr;
32
input [7:0] vl;
33
input [5:0] ven;
34
input thrd;
35
input predict_taken;
36
input [4:0] Rt;
37
output reg [127:0] bus;
38
output reg [4:0] id_o;
39
output reg idv_o;
40
 
41
parameter TRUE = 1'b1;
42
parameter FALSE = 1'b0;
43
 
44
// Really IsPredictableBranch
45
// Does not include BccR's
46
//function IsBranch;
47
//input [47:0] isn;
48
//casez(isn[`INSTRUCTION_OP])
49
//`Bcc:   IsBranch = TRUE;
50
//`BBc:   IsBranch = TRUE;
51
//`BEQI:  IsBranch = TRUE;
52
//`CHK:   IsBranch = TRUE;
53
//default:    IsBranch = FALSE;
54
//endcase
55
//endfunction
56
 
57
wire iAlu;
58
mIsALU uialu1
59
(
60
        .instr(instr),
61
        .IsALU(iAlu)
62
);
63
 
64
 
65
reg IsALU;
66
always @*
67
case(instr[`INSTRUCTION_OP])
68
`R2:    if (instr[`INSTRUCTION_L2]==2'b00)
69
                        case(instr[`INSTRUCTION_S2])
70
                        `VMOV:          IsALU = TRUE;
71
                `RTI:       IsALU = FALSE;
72
                default:    IsALU = TRUE;
73
                endcase
74
            else
75
                IsALU = TRUE;
76
`BRK:   IsALU = FALSE;
77
`Bcc:   IsALU = FALSE;
78
`BBc:   IsALU = FALSE;
79
`BEQI:  IsALU = FALSE;
80
`CHK:   IsALU = FALSE;
81
`JAL:   IsALU = FALSE;
82
`JMP:   IsALU = FALSE;
83
`CALL:  IsALU = FALSE;
84
`RET:   IsALU = FALSE;
85
`FVECTOR:
86
                        case(instr[`INSTRUCTION_S2])
87
            `VSHL,`VSHR,`VASR:  IsALU = TRUE;
88
            default:    IsALU = FALSE;  // Integer
89
            endcase
90
`IVECTOR:
91
                        case(instr[`INSTRUCTION_S2])
92
            `VSHL,`VSHR,`VASR:  IsALU = TRUE;
93
            default:    IsALU = TRUE;  // Integer
94
            endcase
95
`FLOAT:         IsALU = FALSE;
96
default:    IsALU = TRUE;
97
endcase
98
 
99
function IsAlu0Only;
100
input [47:0] isn;
101
begin
102
case(isn[`INSTRUCTION_OP])
103
`R2:
104
        if (isn[`INSTRUCTION_L2]==2'b00)
105
                case(isn[`INSTRUCTION_S2])
106
                `R1:        IsAlu0Only = TRUE;
107
                `SHIFTR,`SHIFT31,`SHIFT63:
108
                        IsAlu0Only = TRUE;
109
                `MULU,`MULSU,`MUL,
110
                `DIVMODU,`DIVMODSU,`DIVMOD: IsAlu0Only = TRUE;
111
                `MIN,`MAX:  IsAlu0Only = TRUE;
112
                default:    IsAlu0Only = FALSE;
113
                endcase
114
        else
115
                IsAlu0Only = FALSE;
116
`MEMNDX:        IsAlu0Only = TRUE;
117
`IVECTOR,`FVECTOR:
118
        case(isn[`INSTRUCTION_S2])
119
        `VSHL,`VSHR,`VASR:  IsAlu0Only = TRUE;
120
        default: IsAlu0Only = FALSE;
121
        endcase
122
`BITFIELD:  IsAlu0Only = TRUE;
123
`MULUI,`MULI,
124
`DIVUI,`DIVI,
125
`MODI:   IsAlu0Only = TRUE;
126
`CSRRW: IsAlu0Only = TRUE;
127
default:    IsAlu0Only = FALSE;
128
endcase
129
end
130
endfunction
131
 
132
function IsFPU;
133
input [47:0] isn;
134
begin
135
case(isn[`INSTRUCTION_OP])
136
`FLOAT: IsFPU = TRUE;
137
`FVECTOR:
138
                    case(isn[`INSTRUCTION_S2])
139
            `VSHL,`VSHR,`VASR:  IsFPU = FALSE;
140
            default:    IsFPU = TRUE;
141
            endcase
142
default:    IsFPU = FALSE;
143
endcase
144
end
145
endfunction
146
 
147
reg IsFlowCtrl;
148
 
149
always @*
150
case(instr[`INSTRUCTION_OP])
151
`BRK:    IsFlowCtrl <= TRUE;
152
`RR:    case(instr[`INSTRUCTION_S2])
153
        `RTI:   IsFlowCtrl <= TRUE;
154
        default:    IsFlowCtrl <= FALSE;
155
        endcase
156
`Bcc:   IsFlowCtrl <= TRUE;
157
`BBc:           IsFlowCtrl <= TRUE;
158
`BEQI:  IsFlowCtrl <= TRUE;
159
`CHK:   IsFlowCtrl <= TRUE;
160
`JAL:   IsFlowCtrl <= TRUE;
161
`JMP:           IsFlowCtrl <= TRUE;
162
`CALL:  IsFlowCtrl <= TRUE;
163
`RET:   IsFlowCtrl <= TRUE;
164
default:    IsFlowCtrl <= FALSE;
165
endcase
166
 
167
//function IsFlowCtrl;
168
//input [47:0] isn;
169
//begin
170
//case(isn[`INSTRUCTION_OP])
171
//`BRK:    IsFlowCtrl = TRUE;
172
//`RR:    case(isn[`INSTRUCTION_S2])
173
//        `RTI:   IsFlowCtrl = TRUE;
174
//        default:    IsFlowCtrl = FALSE;
175
//        endcase
176
//`Bcc:   IsFlowCtrl = TRUE;
177
//`BBc:         IsFlowCtrl = TRUE;
178
//`BEQI:  IsFlowCtrl = TRUE;
179
//`CHK:   IsFlowCtrl = TRUE;
180
//`JAL:   IsFlowCtrl = TRUE;
181
//`JMP:         IsFlowCtrl = TRUE;
182
//`CALL:  IsFlowCtrl = TRUE;
183
//`RET:   IsFlowCtrl = TRUE;
184
//default:    IsFlowCtrl = FALSE;
185
//endcase
186
//end
187
//endfunction
188
 
189
// fnCanException
190
//
191
// Used by memory issue logic.
192
// Returns TRUE if the instruction can cause an exception.
193
// In debug mode any instruction could potentially cause a breakpoint exception.
194
// Rather than check all the addresses for potential debug exceptions it's
195
// simpler to just have it so that all instructions could exception. This will
196
// slow processing down somewhat as stores will only be done at the head of the
197
// instruction queue, but it's debug mode so we probably don't care.
198
//
199
function fnCanException;
200
input [47:0] isn;
201
begin
202
// ToDo add debug_on as input
203
`ifdef SUPPORT_DBG
204
if (debug_on)
205
    fnCanException = `TRUE;
206
else
207
`endif
208
case(isn[`INSTRUCTION_OP])
209
`FLOAT:
210
    case(isn[`INSTRUCTION_S2])
211
    `FDIV,`FMUL,`FADD,`FSUB,`FTX:
212
        fnCanException = `TRUE;
213
    default:    fnCanException = `FALSE;
214
    endcase
215
`ADDI,`DIVI,`MODI,`MULI:
216
    fnCanException = `TRUE;
217
`R2:
218
    case(isn[`INSTRUCTION_S2])
219
    `ADD,`SUB,`MUL,`DIVMOD,`MULSU,`DIVMODSU:   fnCanException = TRUE;
220
    `RTI:   fnCanException = TRUE;
221
    default:    fnCanException = FALSE;
222
    endcase
223
`Bcc:   fnCanException = TRUE;
224
`BEQI:  fnCanException = TRUE;
225
`CHK:   fnCanException = TRUE;
226
default:
227
    fnCanException = IsMem(isn);
228
endcase
229
end
230
endfunction
231
 
232
function IsLoad;
233
input [47:0] isn;
234
case(isn[`INSTRUCTION_OP])
235
`MEMNDX:
236
        if (isn[`INSTRUCTION_L2]==2'b00)
237
            case(isn[`INSTRUCTION_S2])
238
            `LBX:   IsLoad = TRUE;
239
            `LBUX:  IsLoad = TRUE;
240
            `LCX:   IsLoad = TRUE;
241
            `LCUX:  IsLoad = TRUE;
242
            `LHX:   IsLoad = TRUE;
243
            `LHUX:  IsLoad = TRUE;
244
            `LWX:   IsLoad = TRUE;
245
            `LWRX:  IsLoad = TRUE;
246
            `LVX:   IsLoad = TRUE;
247
            `LVx:       IsLoad = TRUE;
248
            default: IsLoad = FALSE;
249
            endcase
250
        else
251
                IsLoad = FALSE;
252
`LB:    IsLoad = TRUE;
253
`LBU:   IsLoad = TRUE;
254
`Lx:    IsLoad = TRUE;
255
`LxU:   IsLoad = TRUE;
256
`LWR:   IsLoad = TRUE;
257
`LV:    IsLoad = TRUE;
258
`LVx:   IsLoad = TRUE;
259
default:    IsLoad = FALSE;
260
endcase
261
endfunction
262
 
263
function [0:0] IsMem;
264
input [47:0] isn;
265
case(isn[`INSTRUCTION_OP])
266
`MEMNDX:        IsMem = TRUE;
267
`AMO:           IsMem = TRUE;
268
`LB:    IsMem = TRUE;
269
`LBU:   IsMem = TRUE;
270
`Lx:    IsMem = TRUE;
271
`LxU:   IsMem = TRUE;
272
`LWR:   IsMem = TRUE;
273
`LV,`SV:    IsMem = TRUE;
274
`INC:           IsMem = TRUE;
275
`SB:    IsMem = TRUE;
276
`Sx:    IsMem = TRUE;
277
`SWC:   IsMem = TRUE;
278
`CAS:   IsMem = TRUE;
279
`LVx:           IsMem = TRUE;
280
default:    IsMem = FALSE;
281
endcase
282
endfunction
283
 
284
function IsMemNdx;
285
input [47:0] isn;
286
case(isn[`INSTRUCTION_OP])
287
`MEMNDX:        IsMemNdx = TRUE;
288
default:    IsMemNdx = FALSE;
289
endcase
290
endfunction
291
 
292
function IsCAS;
293
input [47:0] isn;
294
case(isn[`INSTRUCTION_OP])
295
`MEMNDX:
296
        if (isn[`INSTRUCTION_L2]==2'b00)
297
            case(isn[`INSTRUCTION_S2])
298
            `CASX:   IsCAS = TRUE;
299
            default:    IsCAS = FALSE;
300
            endcase
301
        else
302
                IsCAS = FALSE;
303
`CAS:       IsCAS = TRUE;
304
default:    IsCAS = FALSE;
305
endcase
306
endfunction
307
 
308
function IsAMO;
309
input [47:0] isn;
310
case(isn[`INSTRUCTION_OP])
311
`AMO:       IsAMO = TRUE;
312
default:    IsAMO = FALSE;
313
endcase
314
endfunction
315
 
316
function IsInc;
317
input [47:0] isn;
318
case(isn[`INSTRUCTION_OP])
319
`MEMNDX:
320
        if (isn[`INSTRUCTION_L2]==2'b00)
321
                case(isn[`INSTRUCTION_S2])
322
            `INC:   IsInc = TRUE;
323
            default:    IsInc = FALSE;
324
            endcase
325
        else
326
                IsInc = FALSE;
327
`INC:    IsInc = TRUE;
328
default:    IsInc = FALSE;
329
endcase
330
endfunction
331
 
332
function IsSync;
333
input [47:0] isn;
334
IsSync = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`SYNC);
335
endfunction
336
 
337
function IsFSync;
338
input [47:0] isn;
339
IsFSync = (isn[`INSTRUCTION_OP]==`FLOAT && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`FSYNC);
340
endfunction
341
 
342
function IsMemdb;
343
input [47:0] isn;
344
IsMemdb = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMDB);
345
endfunction
346
 
347
function IsMemsb;
348
input [47:0] isn;
349
IsMemsb = (isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMSB);
350
endfunction
351
 
352
function IsSEI;
353
input [47:0] isn;
354
IsSEI = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`SEI);
355
endfunction
356
 
357
function IsShift48;
358
input [47:0] isn;
359
case(isn[`INSTRUCTION_OP])
360
`R2:
361
        if (isn[`INSTRUCTION_L2]==2'b01)
362
            case(isn[47:42])
363
            `SHIFTR: IsShift48 = TRUE;
364
            default: IsShift48 = FALSE;
365
            endcase
366
    else
367
        IsShift48 = FALSE;
368
default: IsShift48 = FALSE;
369
endcase
370
endfunction
371
 
372
function IsLWRX;
373
input [47:0] isn;
374
case(isn[`INSTRUCTION_OP])
375
`MEMNDX:
376
        if (isn[`INSTRUCTION_L2]==2'b00)
377
            case(isn[`INSTRUCTION_S2])
378
            `LWRX:   IsLWRX = TRUE;
379
            default:    IsLWRX = FALSE;
380
            endcase
381
        else
382
                IsLWRX = FALSE;
383
default:    IsLWRX = FALSE;
384
endcase
385
endfunction
386
 
387
// Aquire / release bits are only available on indexed SWC / LWR
388
function IsSWCX;
389
input [47:0] isn;
390
case(isn[`INSTRUCTION_OP])
391
`MEMNDX:
392
        if (isn[`INSTRUCTION_L2]==2'b00)
393
            case(isn[`INSTRUCTION_S2])
394
            `SWCX:   IsSWCX = TRUE;
395
            default:    IsSWCX = FALSE;
396
            endcase
397
        else
398
                IsSWCX = FALSE;
399
default:    IsSWCX = FALSE;
400
endcase
401
endfunction
402
 
403
function IsJmp;
404
input [47:0] isn;
405
IsJmp = isn[`INSTRUCTION_OP]==`JMP && isn[7]==1'b0;
406
endfunction
407
 
408
// Really IsPredictableBranch
409
// Does not include BccR's
410
function IsBranch;
411
input [47:0] isn;
412
casez(isn[`INSTRUCTION_OP])
413
`Bcc:   IsBranch = TRUE;
414
`BBc:   IsBranch = TRUE;
415
`BEQI:  IsBranch = TRUE;
416
`CHK:   IsBranch = TRUE;
417
default:    IsBranch = FALSE;
418
endcase
419
endfunction
420
 
421
function IsBrk;
422
input [47:0] isn;
423
IsBrk = isn[`INSTRUCTION_OP]==`BRK && isn[`INSTRUCTION_L2]==2'b00;
424
endfunction
425
 
426
function IsRti;
427
input [47:0] isn;
428
IsRti = isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`RTI;
429
endfunction
430
 
431
// Has an extendable 14-bit constant
432
function HasConst;
433
input [47:0] isn;
434
casez(isn[`INSTRUCTION_OP])
435
`ADDI:  HasConst = TRUE;
436
`SLTI:  HasConst = TRUE;
437
`SLTUI: HasConst = TRUE;
438
`SGTI:  HasConst = TRUE;
439
`SGTUI: HasConst = TRUE;
440
`ANDI:  HasConst = TRUE;
441
`ORI:   HasConst = TRUE;
442
`XORI:  HasConst = TRUE;
443
`XNORI: HasConst = TRUE;
444
`MULUI: HasConst = TRUE;
445
`MULI:  HasConst = TRUE;
446
`DIVUI: HasConst = TRUE;
447
`DIVI:  HasConst = TRUE;
448
`MODI:  HasConst = TRUE;
449
`LB:    HasConst = TRUE;
450
`LBU:   HasConst = TRUE;
451
`Lx:    HasConst = TRUE;
452
`LWR:           HasConst = TRUE;
453
`LV:    HasConst = TRUE;
454
`SB:    HasConst = TRUE;
455
`Sx:    HasConst = TRUE;
456
`SWC:   HasConst = TRUE;
457
`INC:           HasConst = TRUE;
458
`SV:    HasConst = TRUE;
459
`CAS:   HasConst = TRUE;
460
`JAL:   HasConst = TRUE;
461
`CALL:  HasConst = TRUE;
462
`RET:   HasConst = TRUE;
463
`LVx:           HasConst = TRUE;
464
default:    HasConst = FALSE;
465
endcase
466
endfunction
467
 
468
function IsRFW;
469
input [47:0] isn;
470
casez(isn[`INSTRUCTION_OP])
471
`IVECTOR:   IsRFW = TRUE;
472
`FVECTOR:   IsRFW = TRUE;
473
`R2:
474
        if (isn[`INSTRUCTION_L2]==2'b00)
475
            case(isn[`INSTRUCTION_S2])
476
            `R1:    IsRFW = TRUE;
477
            `ADD:   IsRFW = TRUE;
478
            `SUB:   IsRFW = TRUE;
479
            `SLT:   IsRFW = TRUE;
480
            `SLTU:  IsRFW = TRUE;
481
            `SLE:   IsRFW = TRUE;
482
            `SLEU:  IsRFW = TRUE;
483
            `AND:   IsRFW = TRUE;
484
            `OR:    IsRFW = TRUE;
485
            `XOR:   IsRFW = TRUE;
486
            `MULU:  IsRFW = TRUE;
487
            `MULSU: IsRFW = TRUE;
488
            `MUL:   IsRFW = TRUE;
489
            `DIVMODU:  IsRFW = TRUE;
490
            `DIVMODSU: IsRFW = TRUE;
491
            `DIVMOD:IsRFW = TRUE;
492
            `MOV:       IsRFW = TRUE;
493
            `VMOV:      IsRFW = TRUE;
494
            `SHIFTR,`SHIFT31,`SHIFT63:
495
                        IsRFW = TRUE;
496
            `MIN,`MAX:    IsRFW = TRUE;
497
            `SEI:       IsRFW = TRUE;
498
            default:    IsRFW = FALSE;
499
            endcase
500
        else
501
                IsRFW = FALSE;
502
`MEMNDX:
503
        if (isn[`INSTRUCTION_L2]==2'b00)
504
            case(isn[`INSTRUCTION_S2])
505
            `LBX:   IsRFW = TRUE;
506
            `LBUX:  IsRFW = TRUE;
507
            `LCX:   IsRFW = TRUE;
508
            `LCUX:  IsRFW = TRUE;
509
            `LHX:   IsRFW = TRUE;
510
            `LHUX:  IsRFW = TRUE;
511
            `LWX:   IsRFW = TRUE;
512
            `LWRX:  IsRFW = TRUE;
513
            `LVX:   IsRFW = TRUE;
514
            `LVx:       IsRFW = TRUE;
515
            `CASX:  IsRFW = TRUE;
516
            default:    IsRFW = FALSE;
517
            endcase
518
        else
519
                IsRFW = FALSE;
520
`BBc:
521
        case(isn[20:19])
522
        `IBNE:  IsRFW = TRUE;
523
        `DBNZ:  IsRFW = TRUE;
524
        default:        IsRFW = FALSE;
525
        endcase
526
`BITFIELD:  IsRFW = TRUE;
527
`ADDI:      IsRFW = TRUE;
528
`SLTI:      IsRFW = TRUE;
529
`SLTUI:     IsRFW = TRUE;
530
`SGTI:      IsRFW = TRUE;
531
`SGTUI:     IsRFW = TRUE;
532
`ANDI:      IsRFW = TRUE;
533
`ORI:       IsRFW = TRUE;
534
`XORI:      IsRFW = TRUE;
535
`MULUI:     IsRFW = TRUE;
536
`MULI:      IsRFW = TRUE;
537
`DIVUI:     IsRFW = TRUE;
538
`DIVI:      IsRFW = TRUE;
539
`MODI:      IsRFW = TRUE;
540
`JAL:       IsRFW = TRUE;
541
`CALL:      IsRFW = TRUE;
542
`RET:       IsRFW = TRUE;
543
`LB:        IsRFW = TRUE;
544
`LBU:       IsRFW = TRUE;
545
`Lx:        IsRFW = TRUE;
546
`LWR:       IsRFW = TRUE;
547
`LV:        IsRFW = TRUE;
548
`LVx:                           IsRFW = TRUE;
549
`CAS:       IsRFW = TRUE;
550
`AMO:                           IsRFW = TRUE;
551
`CSRRW:                 IsRFW = TRUE;
552
default:    IsRFW = FALSE;
553
endcase
554
endfunction
555
 
556
// Determines which lanes of the target register get updated.
557
function [7:0] fnWe;
558
input [47:0] isn;
559
casez(isn[`INSTRUCTION_OP])
560
`R2:
561
        case(isn[`INSTRUCTION_S2])
562
        `R1:
563
                case(isn[22:18])
564
                `ABS,`CNTLZ,`CNTLO,`CNTPOP:
565
                        case(isn[25:23])
566
                        3'b000: fnWe = 8'h01;
567
                        3'b001: fnWe = 8'h03;
568
                        3'b010: fnWe = 8'h0F;
569
                        3'b011: fnWe = 8'hFF;
570
                        default:        fnWe = 8'hFF;
571
                        endcase
572
                default: fnWe = 8'hFF;
573
                endcase
574
        `SHIFT31:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
575
        `SHIFT63:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
576
        `SLT,`SLTU,`SLE,`SLEU,
577
        `ADD,`SUB,
578
        `AND,`OR,`XOR,
579
        `NAND,`NOR,`XNOR,
580
        `DIVMOD,`DIVMODU,`DIVMODSU,
581
        `MUL,`MULU,`MULSU:
582
                case(isn[25:23])
583
                3'b000: fnWe = 8'h01;
584
                3'b001: fnWe = 8'h03;
585
                3'b010: fnWe = 8'h0F;
586
                3'b011: fnWe = 8'hFF;
587
                default:        fnWe = 8'hFF;
588
                endcase
589
        default: fnWe = 8'hFF;
590
        endcase
591
default:        fnWe = 8'hFF;
592
endcase
593
endfunction
594
 
595
// Detect if a source is automatically valid
596
function Source1Valid;
597
input [47:0] isn;
598
casez(isn[`INSTRUCTION_OP])
599
`BRK:   Source1Valid = TRUE;
600
`Bcc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
601
`BBc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
602
`BEQI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
603
`CHK:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
604
`R2:    case(isn[`INSTRUCTION_S2])
605
        `SHIFT31:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
606
        `SHIFT63:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
607
        `SHIFTR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
608
        default:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
609
        endcase
610
`MEMNDX:        Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
611
`ADDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
612
`SLTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
613
`SLTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
614
`SGTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
615
`SGTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
616
`ANDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
617
`ORI:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
618
`XORI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
619
`XNORI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
620
`MULUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
621
`AMO:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
622
`LB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
623
`LBU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
624
`Lx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
625
`LxU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
626
`LWR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
627
`LV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
628
`LVx:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
629
`SB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
630
`Sx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
631
`SWC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
632
`SV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
633
`INC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
634
`CAS:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
635
`JAL:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
636
`RET:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
637
`CSRRW: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
638
`BITFIELD:      case(isn[31:28])
639
                        `BFINSI:        Source1Valid = TRUE;
640
                        default:        Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
641
                        endcase
642
`IVECTOR:
643
                        Source1Valid = FALSE;
644
default:    Source1Valid = TRUE;
645
endcase
646
endfunction
647
 
648
function Source2Valid;
649
input [47:0] isn;
650
casez(isn[`INSTRUCTION_OP])
651
`BRK:   Source2Valid = TRUE;
652
`Bcc:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
653
`BBc:   Source2Valid = TRUE;
654
`BEQI:  Source2Valid = TRUE;
655
`CHK:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
656
`R2:    case(isn[`INSTRUCTION_S2])
657
        `R1:       Source2Valid = TRUE;
658
        `SHIFTR:   Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
659
        `SHIFT31:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
660
        `SHIFT63:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
661
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
662
        endcase
663
`MEMNDX: case(isn[`INSTRUCTION_S2])
664
        `LVX,`SVX: Source2Valid = FALSE;
665
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
666
        endcase
667
`ADDI:  Source2Valid = TRUE;
668
`SLTI:  Source2Valid = TRUE;
669
`SLTUI: Source2Valid = TRUE;
670
`SGTI:  Source2Valid = TRUE;
671
`SGTUI: Source2Valid = TRUE;
672
`ANDI:  Source2Valid = TRUE;
673
`ORI:   Source2Valid = TRUE;
674
`XORI:  Source2Valid = TRUE;
675
`XNORI: Source2Valid = TRUE;
676
`MULUI: Source2Valid = TRUE;
677
`LB:    Source2Valid = TRUE;
678
`LBU:   Source2Valid = TRUE;
679
`Lx:    Source2Valid = TRUE;
680
`LxU:   Source2Valid = TRUE;
681
`LWR:   Source2Valid = TRUE;
682
`LVx:   Source2Valid = TRUE;
683
`INC:           Source2Valid = TRUE;
684
`SB:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
685
`Sx:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
686
`SWC:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
687
`CAS:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
688
`JAL:   Source2Valid = TRUE;
689
`RET:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
690
`IVECTOR:
691
                    case(isn[`INSTRUCTION_S2])
692
            `VABS:  Source2Valid = TRUE;
693
            `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
694
                Source2Valid = FALSE;
695
            `VADDS,`VSUBS,`VANDS,`VORS,`VXORS:
696
                Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
697
            `VBITS2V:   Source2Valid = TRUE;
698
            `V2BITS:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
699
            `VSHL,`VSHR,`VASR:  Source2Valid = isn[22:21]==2'd2;
700
            default:    Source2Valid = FALSE;
701
            endcase
702
`LV:        Source2Valid = TRUE;
703
`SV:        Source2Valid = FALSE;
704
`AMO:           Source2Valid = isn[31] || isn[`INSTRUCTION_RB]==5'd0;
705
default:    Source2Valid = TRUE;
706
endcase
707
endfunction
708
 
709
function Source3Valid;
710
input [47:0] isn;
711
case(isn[`INSTRUCTION_OP])
712
`IVECTOR:
713
    case(isn[`INSTRUCTION_S2])
714
    `VEX:       Source3Valid = TRUE;
715
    default:    Source3Valid = TRUE;
716
    endcase
717
`CHK:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
718
`R2:
719
        if (isn[`INSTRUCTION_L2]==2'b01)
720
                case(isn[47:42])
721
    `CMOVEZ,`CMOVNZ:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
722
                default:        Source3Valid = TRUE;
723
                endcase
724
        else
725
    case(isn[`INSTRUCTION_S2])
726
    `MAJ:               Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
727
    default:    Source3Valid = TRUE;
728
    endcase
729
`MEMNDX:
730
        if (isn[`INSTRUCTION_L2]==2'b00)
731
    case(isn[`INSTRUCTION_S2])
732
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
733
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
734
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
735
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
736
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
737
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
738
    default:    Source3Valid = TRUE;
739
    endcase
740
default:    Source3Valid = TRUE;
741
endcase
742
endfunction
743
 
744
always @(posedge clk)
745
begin
746
        bus <= 128'h0;
747
        bus[`IB_CONST] <= instr[7:6]==2'b01 ? {{34{instr[47]}},instr[47:18]} :
748
                                                                                                                                                                {{50{instr[31]}},instr[31:18]};
749
        case(instr[7:6])
750
        2'b00:  bus[`IB_LN] <= 3'd4;
751
        2'b01:  bus[`IB_LN] <= 3'd6;
752
        default: bus[`IB_LN] <= 3'd2;
753
        endcase
754
//      bus[`IB_RT]              <= fnRt(instr,ven,vl,thrd) | {thrd,7'b0};
755
//      bus[`IB_RC]              <= fnRc(instr,ven,thrd) | {thrd,7'b0};
756
//      bus[`IB_RA]              <= fnRa(instr,ven,vl,thrd) | {thrd,7'b0};
757
        bus[`IB_IMM]     <= HasConst(instr);
758
        bus[`IB_A3V]   <= Source3Valid(instr);
759
        bus[`IB_A2V]   <= Source2Valid(instr);
760
        bus[`IB_A1V]   <= Source1Valid(instr);
761
        bus[`IB_BT]    <= (IsBranch(instr) && predict_taken);
762
        bus[`IB_ALU]   <= IsALU;
763
        bus[`IB_ALU0]  <= IsAlu0Only(instr);
764
        bus[`IB_FPU]   <= IsFPU(instr);
765
        bus[`IB_FC]              <= IsFlowCtrl;
766
        bus[`IB_CANEX] <= fnCanException(instr);
767
        bus[`IB_LOAD]    <= IsLoad(instr);
768
        bus[`IB_PRELOAD] <=   IsLoad(instr) && Rt==5'd0;
769
        bus[`IB_MEM]            <= IsMem(instr);
770
        bus[`IB_MEMNDX] <= IsMemNdx(instr);
771
        bus[`IB_RMW]            <= IsCAS(instr) || IsAMO(instr) || IsInc(instr);
772
        bus[`IB_MEMDB]  <= IsMemdb(instr);
773
        bus[`IB_MEMSB]  <= IsMemsb(instr);
774
        bus[`IB_SHFT48] <= IsShift48(instr);
775
        bus[`IB_SEI]            <= IsSEI(instr);
776
        bus[`IB_AQ]                     <= (IsAMO(instr)|IsLWRX(instr)|IsSWCX(instr)) & instr[25];
777
        bus[`IB_RL]                     <= (IsAMO(instr)|IsLWRX(instr)|IsSWCX(instr)) & instr[24];
778
        bus[`IB_JMP]            <= IsJmp(instr);
779
        bus[`IB_BR]                     <= IsBranch(instr);
780
        bus[`IB_SYNC]           <= IsSync(instr)||IsBrk(instr)||IsRti(instr);
781
        bus[`IB_FSYNC]  <= IsFSync(instr);
782
        bus[`IB_RFW]            <= Rt==5'd0 ? 1'b0 : IsRFW(instr);
783
        bus[`IB_WE]                     <= fnWe(instr);
784
        id_o <= id_i;
785
        idv_o <= idv_i;
786
end
787
 
788
endmodule
789
 
790
module mIsALU(instr, IsALU);
791
input [47:0] instr;
792
output reg IsALU;
793
parameter TRUE = 1'b1;
794
parameter FALSE = 1'b0;
795
 
796
always @*
797
casez(instr[`INSTRUCTION_OP])
798
`R2:    if (instr[`INSTRUCTION_L2]==2'b00)
799
                        case(instr[`INSTRUCTION_S2])
800
                        `VMOV:          IsALU = TRUE;
801
                `RTI:       IsALU = FALSE;
802
                default:    IsALU = TRUE;
803
                endcase
804
            else
805
                IsALU = TRUE;
806
`BRK:   IsALU = FALSE;
807
`Bcc:   IsALU = FALSE;
808
`BBc:   IsALU = FALSE;
809
`BEQI:  IsALU = FALSE;
810
`CHK:   IsALU = FALSE;
811
`JAL:   IsALU = FALSE;
812
`JMP:   IsALU = FALSE;
813
`CALL:  IsALU = FALSE;
814
`RET:   IsALU = FALSE;
815
`FVECTOR:
816
                        case(instr[`INSTRUCTION_S2])
817
            `VSHL,`VSHR,`VASR:  IsALU = TRUE;
818
            default:    IsALU = FALSE;  // Integer
819
            endcase
820
`IVECTOR:
821
                        case(instr[`INSTRUCTION_S2])
822
            `VSHL,`VSHR,`VASR:  IsALU = TRUE;
823
            default:    IsALU = TRUE;  // Integer
824
            endcase
825
`FLOAT:         IsALU = FALSE;
826
default:    IsALU = TRUE;
827
endcase
828
 
829
endmodule

powered by: WebSVN 2.1.0

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