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

Subversion Repositories thor

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

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

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2017-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      FT64_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 49 robfinch
`R2:    case(instr[`INSTRUCTION_S2])
153 48 robfinch
        `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 49 robfinch
// Stores can stil exception if there is a write buffer, but we allow following
228
// stores to be issued by ignoring the fact they can exception because the stores
229
// can be undone by invalidating the write buffer.
230
`ifdef HAS_WB
231
    fnCanException = IsLoad(isn);
232
`else
233 48 robfinch
    fnCanException = IsMem(isn);
234 49 robfinch
`endif
235 48 robfinch
endcase
236
end
237
endfunction
238
 
239
function IsLoad;
240
input [47:0] isn;
241
case(isn[`INSTRUCTION_OP])
242
`MEMNDX:
243
        if (isn[`INSTRUCTION_L2]==2'b00)
244
            case(isn[`INSTRUCTION_S2])
245
            `LBX:   IsLoad = TRUE;
246
            `LBUX:  IsLoad = TRUE;
247
            `LCX:   IsLoad = TRUE;
248
            `LCUX:  IsLoad = TRUE;
249
            `LHX:   IsLoad = TRUE;
250
            `LHUX:  IsLoad = TRUE;
251
            `LWX:   IsLoad = TRUE;
252
            `LWRX:  IsLoad = TRUE;
253
            `LVX:   IsLoad = TRUE;
254
            `LVx:       IsLoad = TRUE;
255
            default: IsLoad = FALSE;
256
            endcase
257
        else
258
                IsLoad = FALSE;
259
`LB:    IsLoad = TRUE;
260
`LBU:   IsLoad = TRUE;
261
`Lx:    IsLoad = TRUE;
262
`LxU:   IsLoad = TRUE;
263
`LWR:   IsLoad = TRUE;
264
`LV:    IsLoad = TRUE;
265
`LVx:   IsLoad = TRUE;
266
default:    IsLoad = FALSE;
267
endcase
268
endfunction
269
 
270
function [0:0] IsMem;
271
input [47:0] isn;
272
case(isn[`INSTRUCTION_OP])
273
`MEMNDX:        IsMem = TRUE;
274
`AMO:           IsMem = TRUE;
275
`LB:    IsMem = TRUE;
276
`LBU:   IsMem = TRUE;
277
`Lx:    IsMem = TRUE;
278
`LxU:   IsMem = TRUE;
279
`LWR:   IsMem = TRUE;
280
`LV,`SV:    IsMem = TRUE;
281
`INC:           IsMem = TRUE;
282
`SB:    IsMem = TRUE;
283
`Sx:    IsMem = TRUE;
284
`SWC:   IsMem = TRUE;
285
`CAS:   IsMem = TRUE;
286
`LVx:           IsMem = TRUE;
287
default:    IsMem = FALSE;
288
endcase
289
endfunction
290
 
291
function IsMemNdx;
292
input [47:0] isn;
293
case(isn[`INSTRUCTION_OP])
294
`MEMNDX:        IsMemNdx = TRUE;
295
default:    IsMemNdx = FALSE;
296
endcase
297
endfunction
298
 
299
function IsCAS;
300
input [47:0] isn;
301
case(isn[`INSTRUCTION_OP])
302
`MEMNDX:
303
        if (isn[`INSTRUCTION_L2]==2'b00)
304
            case(isn[`INSTRUCTION_S2])
305
            `CASX:   IsCAS = TRUE;
306
            default:    IsCAS = FALSE;
307
            endcase
308
        else
309
                IsCAS = FALSE;
310
`CAS:       IsCAS = TRUE;
311
default:    IsCAS = FALSE;
312
endcase
313
endfunction
314
 
315
function IsAMO;
316
input [47:0] isn;
317
case(isn[`INSTRUCTION_OP])
318
`AMO:       IsAMO = TRUE;
319
default:    IsAMO = FALSE;
320
endcase
321
endfunction
322
 
323
function IsInc;
324
input [47:0] isn;
325
case(isn[`INSTRUCTION_OP])
326
`MEMNDX:
327
        if (isn[`INSTRUCTION_L2]==2'b00)
328
                case(isn[`INSTRUCTION_S2])
329
            `INC:   IsInc = TRUE;
330
            default:    IsInc = FALSE;
331
            endcase
332
        else
333
                IsInc = FALSE;
334
`INC:    IsInc = TRUE;
335
default:    IsInc = FALSE;
336
endcase
337
endfunction
338
 
339
function IsSync;
340
input [47:0] isn;
341
IsSync = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`SYNC);
342
endfunction
343
 
344
function IsFSync;
345
input [47:0] isn;
346
IsFSync = (isn[`INSTRUCTION_OP]==`FLOAT && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`FSYNC);
347
endfunction
348
 
349
function IsMemdb;
350
input [47:0] isn;
351
IsMemdb = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMDB);
352
endfunction
353
 
354
function IsMemsb;
355
input [47:0] isn;
356
IsMemsb = (isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMSB);
357
endfunction
358
 
359
function IsSEI;
360
input [47:0] isn;
361
IsSEI = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`SEI);
362
endfunction
363
 
364
function IsShift48;
365
input [47:0] isn;
366
case(isn[`INSTRUCTION_OP])
367
`R2:
368
        if (isn[`INSTRUCTION_L2]==2'b01)
369
            case(isn[47:42])
370
            `SHIFTR: IsShift48 = TRUE;
371
            default: IsShift48 = FALSE;
372
            endcase
373
    else
374
        IsShift48 = FALSE;
375
default: IsShift48 = FALSE;
376
endcase
377
endfunction
378
 
379
function IsLWRX;
380
input [47:0] isn;
381
case(isn[`INSTRUCTION_OP])
382
`MEMNDX:
383
        if (isn[`INSTRUCTION_L2]==2'b00)
384
            case(isn[`INSTRUCTION_S2])
385
            `LWRX:   IsLWRX = TRUE;
386
            default:    IsLWRX = FALSE;
387
            endcase
388
        else
389
                IsLWRX = FALSE;
390
default:    IsLWRX = FALSE;
391
endcase
392
endfunction
393
 
394
// Aquire / release bits are only available on indexed SWC / LWR
395
function IsSWCX;
396
input [47:0] isn;
397
case(isn[`INSTRUCTION_OP])
398
`MEMNDX:
399
        if (isn[`INSTRUCTION_L2]==2'b00)
400
            case(isn[`INSTRUCTION_S2])
401
            `SWCX:   IsSWCX = TRUE;
402
            default:    IsSWCX = FALSE;
403
            endcase
404
        else
405
                IsSWCX = FALSE;
406
default:    IsSWCX = FALSE;
407
endcase
408
endfunction
409
 
410
function IsJmp;
411
input [47:0] isn;
412
IsJmp = isn[`INSTRUCTION_OP]==`JMP && isn[7]==1'b0;
413
endfunction
414
 
415
// Really IsPredictableBranch
416
// Does not include BccR's
417
function IsBranch;
418
input [47:0] isn;
419
casez(isn[`INSTRUCTION_OP])
420
`Bcc:   IsBranch = TRUE;
421
`BBc:   IsBranch = TRUE;
422
`BEQI:  IsBranch = TRUE;
423
`CHK:   IsBranch = TRUE;
424
default:    IsBranch = FALSE;
425
endcase
426
endfunction
427
 
428
function IsBrk;
429
input [47:0] isn;
430
IsBrk = isn[`INSTRUCTION_OP]==`BRK && isn[`INSTRUCTION_L2]==2'b00;
431
endfunction
432
 
433
function IsRti;
434
input [47:0] isn;
435
IsRti = isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`RTI;
436
endfunction
437
 
438
// Has an extendable 14-bit constant
439
function HasConst;
440
input [47:0] isn;
441
casez(isn[`INSTRUCTION_OP])
442
`ADDI:  HasConst = TRUE;
443
`SLTI:  HasConst = TRUE;
444
`SLTUI: HasConst = TRUE;
445
`SGTI:  HasConst = TRUE;
446
`SGTUI: HasConst = TRUE;
447
`ANDI:  HasConst = TRUE;
448
`ORI:   HasConst = TRUE;
449
`XORI:  HasConst = TRUE;
450
`XNORI: HasConst = TRUE;
451
`MULUI: HasConst = TRUE;
452
`MULI:  HasConst = TRUE;
453
`DIVUI: HasConst = TRUE;
454
`DIVI:  HasConst = TRUE;
455
`MODI:  HasConst = TRUE;
456
`LB:    HasConst = TRUE;
457
`LBU:   HasConst = TRUE;
458
`Lx:    HasConst = TRUE;
459
`LWR:           HasConst = TRUE;
460
`LV:    HasConst = TRUE;
461
`SB:    HasConst = TRUE;
462
`Sx:    HasConst = TRUE;
463
`SWC:   HasConst = TRUE;
464
`INC:           HasConst = TRUE;
465
`SV:    HasConst = TRUE;
466
`CAS:   HasConst = TRUE;
467
`JAL:   HasConst = TRUE;
468
`CALL:  HasConst = TRUE;
469
`RET:   HasConst = TRUE;
470
`LVx:           HasConst = TRUE;
471
default:    HasConst = FALSE;
472
endcase
473
endfunction
474
 
475
function IsRFW;
476
input [47:0] isn;
477
casez(isn[`INSTRUCTION_OP])
478
`IVECTOR:   IsRFW = TRUE;
479
`FVECTOR:   IsRFW = TRUE;
480
`R2:
481
        if (isn[`INSTRUCTION_L2]==2'b00)
482
            case(isn[`INSTRUCTION_S2])
483
            `R1:    IsRFW = TRUE;
484
            `ADD:   IsRFW = TRUE;
485
            `SUB:   IsRFW = TRUE;
486
            `SLT:   IsRFW = TRUE;
487
            `SLTU:  IsRFW = TRUE;
488
            `SLE:   IsRFW = TRUE;
489
            `SLEU:  IsRFW = TRUE;
490
            `AND:   IsRFW = TRUE;
491
            `OR:    IsRFW = TRUE;
492
            `XOR:   IsRFW = TRUE;
493
            `MULU:  IsRFW = TRUE;
494
            `MULSU: IsRFW = TRUE;
495
            `MUL:   IsRFW = TRUE;
496
            `DIVMODU:  IsRFW = TRUE;
497
            `DIVMODSU: IsRFW = TRUE;
498
            `DIVMOD:IsRFW = TRUE;
499
            `MOV:       IsRFW = TRUE;
500
            `VMOV:      IsRFW = TRUE;
501
            `SHIFTR,`SHIFT31,`SHIFT63:
502
                        IsRFW = TRUE;
503
            `MIN,`MAX:    IsRFW = TRUE;
504
            `SEI:       IsRFW = TRUE;
505
            default:    IsRFW = FALSE;
506
            endcase
507
        else
508
                IsRFW = FALSE;
509
`MEMNDX:
510
        if (isn[`INSTRUCTION_L2]==2'b00)
511
            case(isn[`INSTRUCTION_S2])
512
            `LBX:   IsRFW = TRUE;
513
            `LBUX:  IsRFW = TRUE;
514
            `LCX:   IsRFW = TRUE;
515
            `LCUX:  IsRFW = TRUE;
516
            `LHX:   IsRFW = TRUE;
517
            `LHUX:  IsRFW = TRUE;
518
            `LWX:   IsRFW = TRUE;
519
            `LWRX:  IsRFW = TRUE;
520
            `LVX:   IsRFW = TRUE;
521
            `LVx:       IsRFW = TRUE;
522
            `CASX:  IsRFW = TRUE;
523
            default:    IsRFW = FALSE;
524
            endcase
525
        else
526
                IsRFW = FALSE;
527
`BBc:
528
        case(isn[20:19])
529
        `IBNE:  IsRFW = TRUE;
530
        `DBNZ:  IsRFW = TRUE;
531
        default:        IsRFW = FALSE;
532
        endcase
533
`BITFIELD:  IsRFW = TRUE;
534
`ADDI:      IsRFW = TRUE;
535
`SLTI:      IsRFW = TRUE;
536
`SLTUI:     IsRFW = TRUE;
537
`SGTI:      IsRFW = TRUE;
538
`SGTUI:     IsRFW = TRUE;
539
`ANDI:      IsRFW = TRUE;
540
`ORI:       IsRFW = TRUE;
541
`XORI:      IsRFW = TRUE;
542
`MULUI:     IsRFW = TRUE;
543
`MULI:      IsRFW = TRUE;
544
`DIVUI:     IsRFW = TRUE;
545
`DIVI:      IsRFW = TRUE;
546
`MODI:      IsRFW = TRUE;
547
`JAL:       IsRFW = TRUE;
548
`CALL:      IsRFW = TRUE;
549
`RET:       IsRFW = TRUE;
550
`LB:        IsRFW = TRUE;
551
`LBU:       IsRFW = TRUE;
552
`Lx:        IsRFW = TRUE;
553
`LWR:       IsRFW = TRUE;
554
`LV:        IsRFW = TRUE;
555
`LVx:                           IsRFW = TRUE;
556
`CAS:       IsRFW = TRUE;
557
`AMO:                           IsRFW = TRUE;
558
`CSRRW:                 IsRFW = TRUE;
559
default:    IsRFW = FALSE;
560
endcase
561
endfunction
562
 
563
// Determines which lanes of the target register get updated.
564
function [7:0] fnWe;
565
input [47:0] isn;
566
casez(isn[`INSTRUCTION_OP])
567
`R2:
568
        case(isn[`INSTRUCTION_S2])
569
        `R1:
570
                case(isn[22:18])
571
                `ABS,`CNTLZ,`CNTLO,`CNTPOP:
572
                        case(isn[25:23])
573
                        3'b000: fnWe = 8'h01;
574
                        3'b001: fnWe = 8'h03;
575
                        3'b010: fnWe = 8'h0F;
576
                        3'b011: fnWe = 8'hFF;
577
                        default:        fnWe = 8'hFF;
578
                        endcase
579
                default: fnWe = 8'hFF;
580
                endcase
581
        `SHIFT31:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
582
        `SHIFT63:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
583
        `SLT,`SLTU,`SLE,`SLEU,
584
        `ADD,`SUB,
585
        `AND,`OR,`XOR,
586
        `NAND,`NOR,`XNOR,
587
        `DIVMOD,`DIVMODU,`DIVMODSU,
588
        `MUL,`MULU,`MULSU:
589
                case(isn[25:23])
590
                3'b000: fnWe = 8'h01;
591
                3'b001: fnWe = 8'h03;
592
                3'b010: fnWe = 8'h0F;
593
                3'b011: fnWe = 8'hFF;
594
                default:        fnWe = 8'hFF;
595
                endcase
596
        default: fnWe = 8'hFF;
597
        endcase
598
default:        fnWe = 8'hFF;
599
endcase
600
endfunction
601
 
602
// Detect if a source is automatically valid
603
function Source1Valid;
604
input [47:0] isn;
605
casez(isn[`INSTRUCTION_OP])
606
`BRK:   Source1Valid = TRUE;
607
`Bcc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
608
`BBc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
609
`BEQI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
610
`CHK:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
611
`R2:    case(isn[`INSTRUCTION_S2])
612
        `SHIFT31:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
613
        `SHIFT63:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
614
        `SHIFTR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
615
        default:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
616
        endcase
617
`MEMNDX:        Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
618
`ADDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
619
`SLTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
620
`SLTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
621
`SGTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
622
`SGTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
623
`ANDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
624
`ORI:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
625
`XORI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
626
`XNORI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
627
`MULUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
628
`AMO:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
629
`LB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
630
`LBU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
631
`Lx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
632
`LxU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
633
`LWR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
634
`LV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
635
`LVx:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
636
`SB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
637
`Sx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
638
`SWC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
639
`SV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
640
`INC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
641
`CAS:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
642
`JAL:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
643
`RET:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
644
`CSRRW: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
645
`BITFIELD:      case(isn[31:28])
646
                        `BFINSI:        Source1Valid = TRUE;
647
                        default:        Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
648
                        endcase
649
`IVECTOR:
650
                        Source1Valid = FALSE;
651
default:    Source1Valid = TRUE;
652
endcase
653
endfunction
654
 
655
function Source2Valid;
656
input [47:0] isn;
657
casez(isn[`INSTRUCTION_OP])
658
`BRK:   Source2Valid = TRUE;
659
`Bcc:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
660
`BBc:   Source2Valid = TRUE;
661
`BEQI:  Source2Valid = TRUE;
662
`CHK:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
663
`R2:    case(isn[`INSTRUCTION_S2])
664
        `R1:       Source2Valid = TRUE;
665
        `SHIFTR:   Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
666
        `SHIFT31:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
667
        `SHIFT63:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
668
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
669
        endcase
670
`MEMNDX: case(isn[`INSTRUCTION_S2])
671
        `LVX,`SVX: Source2Valid = FALSE;
672
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
673
        endcase
674
`ADDI:  Source2Valid = TRUE;
675
`SLTI:  Source2Valid = TRUE;
676
`SLTUI: Source2Valid = TRUE;
677
`SGTI:  Source2Valid = TRUE;
678
`SGTUI: Source2Valid = TRUE;
679
`ANDI:  Source2Valid = TRUE;
680
`ORI:   Source2Valid = TRUE;
681
`XORI:  Source2Valid = TRUE;
682
`XNORI: Source2Valid = TRUE;
683
`MULUI: Source2Valid = TRUE;
684
`LB:    Source2Valid = TRUE;
685
`LBU:   Source2Valid = TRUE;
686
`Lx:    Source2Valid = TRUE;
687
`LxU:   Source2Valid = TRUE;
688
`LWR:   Source2Valid = TRUE;
689
`LVx:   Source2Valid = TRUE;
690
`INC:           Source2Valid = TRUE;
691
`SB:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
692
`Sx:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
693
`SWC:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
694
`CAS:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
695
`JAL:   Source2Valid = TRUE;
696
`RET:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
697
`IVECTOR:
698
                    case(isn[`INSTRUCTION_S2])
699
            `VABS:  Source2Valid = TRUE;
700
            `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
701
                Source2Valid = FALSE;
702
            `VADDS,`VSUBS,`VANDS,`VORS,`VXORS:
703
                Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
704
            `VBITS2V:   Source2Valid = TRUE;
705
            `V2BITS:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
706
            `VSHL,`VSHR,`VASR:  Source2Valid = isn[22:21]==2'd2;
707
            default:    Source2Valid = FALSE;
708
            endcase
709
`LV:        Source2Valid = TRUE;
710
`SV:        Source2Valid = FALSE;
711
`AMO:           Source2Valid = isn[31] || isn[`INSTRUCTION_RB]==5'd0;
712
default:    Source2Valid = TRUE;
713
endcase
714
endfunction
715
 
716
function Source3Valid;
717
input [47:0] isn;
718
case(isn[`INSTRUCTION_OP])
719
`IVECTOR:
720
    case(isn[`INSTRUCTION_S2])
721
    `VEX:       Source3Valid = TRUE;
722
    default:    Source3Valid = TRUE;
723
    endcase
724
`CHK:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
725
`R2:
726
        if (isn[`INSTRUCTION_L2]==2'b01)
727
                case(isn[47:42])
728
    `CMOVEZ,`CMOVNZ:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
729
                default:        Source3Valid = TRUE;
730
                endcase
731
        else
732
    case(isn[`INSTRUCTION_S2])
733
    `MAJ:               Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
734
    default:    Source3Valid = TRUE;
735
    endcase
736
`MEMNDX:
737
        if (isn[`INSTRUCTION_L2]==2'b00)
738
    case(isn[`INSTRUCTION_S2])
739
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
740
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
741
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
742
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
743
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
744
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
745
    default:    Source3Valid = TRUE;
746
    endcase
747
default:    Source3Valid = TRUE;
748
endcase
749
endfunction
750
 
751
always @(posedge clk)
752
begin
753
        bus <= 128'h0;
754
        bus[`IB_CONST] <= instr[7:6]==2'b01 ? {{34{instr[47]}},instr[47:18]} :
755
                                                                                                                                                                {{50{instr[31]}},instr[31:18]};
756
        case(instr[7:6])
757
        2'b00:  bus[`IB_LN] <= 3'd4;
758
        2'b01:  bus[`IB_LN] <= 3'd6;
759
        default: bus[`IB_LN] <= 3'd2;
760
        endcase
761
//      bus[`IB_RT]              <= fnRt(instr,ven,vl,thrd) | {thrd,7'b0};
762
//      bus[`IB_RC]              <= fnRc(instr,ven,thrd) | {thrd,7'b0};
763
//      bus[`IB_RA]              <= fnRa(instr,ven,vl,thrd) | {thrd,7'b0};
764
        bus[`IB_IMM]     <= HasConst(instr);
765
        bus[`IB_A3V]   <= Source3Valid(instr);
766
        bus[`IB_A2V]   <= Source2Valid(instr);
767
        bus[`IB_A1V]   <= Source1Valid(instr);
768
        bus[`IB_BT]    <= (IsBranch(instr) && predict_taken);
769
        bus[`IB_ALU]   <= IsALU;
770
        bus[`IB_ALU0]  <= IsAlu0Only(instr);
771
        bus[`IB_FPU]   <= IsFPU(instr);
772
        bus[`IB_FC]              <= IsFlowCtrl;
773
        bus[`IB_CANEX] <= fnCanException(instr);
774
        bus[`IB_LOAD]    <= IsLoad(instr);
775
        bus[`IB_PRELOAD] <=   IsLoad(instr) && Rt==5'd0;
776
        bus[`IB_MEM]            <= IsMem(instr);
777
        bus[`IB_MEMNDX] <= IsMemNdx(instr);
778
        bus[`IB_RMW]            <= IsCAS(instr) || IsAMO(instr) || IsInc(instr);
779
        bus[`IB_MEMDB]  <= IsMemdb(instr);
780
        bus[`IB_MEMSB]  <= IsMemsb(instr);
781
        bus[`IB_SHFT48] <= IsShift48(instr);
782
        bus[`IB_SEI]            <= IsSEI(instr);
783
        bus[`IB_AQ]                     <= (IsAMO(instr)|IsLWRX(instr)|IsSWCX(instr)) & instr[25];
784
        bus[`IB_RL]                     <= (IsAMO(instr)|IsLWRX(instr)|IsSWCX(instr)) & instr[24];
785
        bus[`IB_JMP]            <= IsJmp(instr);
786
        bus[`IB_BR]                     <= IsBranch(instr);
787
        bus[`IB_SYNC]           <= IsSync(instr)||IsBrk(instr)||IsRti(instr);
788
        bus[`IB_FSYNC]  <= IsFSync(instr);
789
        bus[`IB_RFW]            <= Rt==5'd0 ? 1'b0 : IsRFW(instr);
790
        bus[`IB_WE]                     <= fnWe(instr);
791
        id_o <= id_i;
792
        idv_o <= idv_i;
793
end
794
 
795
endmodule
796
 
797
module mIsALU(instr, IsALU);
798
input [47:0] instr;
799
output reg IsALU;
800
parameter TRUE = 1'b1;
801
parameter FALSE = 1'b0;
802
 
803
always @*
804
casez(instr[`INSTRUCTION_OP])
805
`R2:    if (instr[`INSTRUCTION_L2]==2'b00)
806
                        case(instr[`INSTRUCTION_S2])
807
                        `VMOV:          IsALU = TRUE;
808
                `RTI:       IsALU = FALSE;
809
                default:    IsALU = TRUE;
810
                endcase
811
            else
812
                IsALU = TRUE;
813
`BRK:   IsALU = FALSE;
814
`Bcc:   IsALU = FALSE;
815
`BBc:   IsALU = FALSE;
816
`BEQI:  IsALU = FALSE;
817
`CHK:   IsALU = FALSE;
818
`JAL:   IsALU = FALSE;
819
`JMP:   IsALU = FALSE;
820
`CALL:  IsALU = FALSE;
821
`RET:   IsALU = FALSE;
822
`FVECTOR:
823
                        case(instr[`INSTRUCTION_S2])
824
            `VSHL,`VSHR,`VASR:  IsALU = TRUE;
825
            default:    IsALU = FALSE;  // Integer
826
            endcase
827
`IVECTOR:
828
                        case(instr[`INSTRUCTION_S2])
829
            `VSHL,`VSHR,`VASR:  IsALU = TRUE;
830
            default:    IsALU = TRUE;  // Integer
831
            endcase
832
`FLOAT:         IsALU = FALSE;
833
default:    IsALU = TRUE;
834
endcase
835
 
836
endmodule

powered by: WebSVN 2.1.0

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