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

Subversion Repositories thor

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

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 51 robfinch
output reg [143:0] bus;
38 48 robfinch
output reg [4:0] id_o;
39
output reg idv_o;
40
 
41
parameter TRUE = 1'b1;
42
parameter FALSE = 1'b0;
43 50 robfinch
// Memory access sizes
44
parameter byt = 3'd0;
45
parameter wyde = 3'd1;
46
parameter tetra = 3'd2;
47
parameter octa = 3'd3;
48 48 robfinch
 
49
// Really IsPredictableBranch
50
// Does not include BccR's
51
//function IsBranch;
52
//input [47:0] isn;
53
//casez(isn[`INSTRUCTION_OP])
54
//`Bcc:   IsBranch = TRUE;
55
//`BBc:   IsBranch = TRUE;
56
//`BEQI:  IsBranch = TRUE;
57
//`CHK:   IsBranch = TRUE;
58
//default:    IsBranch = FALSE;
59
//endcase
60
//endfunction
61
 
62
wire iAlu;
63
mIsALU uialu1
64
(
65
        .instr(instr),
66
        .IsALU(iAlu)
67
);
68
 
69
 
70
reg IsALU;
71
always @*
72
case(instr[`INSTRUCTION_OP])
73 50 robfinch
`R2:
74
        if (instr[`INSTRUCTION_L2]==2'b00)
75
                case(instr[`INSTRUCTION_S2])
76
                `VMOV:          IsALU = TRUE;
77
    `RTI:       IsALU = FALSE;
78
    default:    IsALU = TRUE;
79
    endcase
80
  else
81
        IsALU = TRUE;
82 48 robfinch
`BRK:   IsALU = FALSE;
83
`Bcc:   IsALU = FALSE;
84
`BBc:   IsALU = FALSE;
85
`BEQI:  IsALU = FALSE;
86
`CHK:   IsALU = FALSE;
87
`JAL:   IsALU = FALSE;
88
`JMP:   IsALU = FALSE;
89
`CALL:  IsALU = FALSE;
90
`RET:   IsALU = FALSE;
91
`FVECTOR:
92 50 robfinch
        case(instr[`INSTRUCTION_S2])
93
  `VSHL,`VSHR,`VASR:  IsALU = TRUE;
94
  default:    IsALU = FALSE;  // Integer
95
  endcase
96 48 robfinch
`IVECTOR:
97 50 robfinch
        case(instr[`INSTRUCTION_S2])
98
  `VSHL,`VSHR,`VASR:  IsALU = TRUE;
99
  default:    IsALU = TRUE;  // Integer
100
  endcase
101 48 robfinch
`FLOAT:         IsALU = FALSE;
102
default:    IsALU = TRUE;
103
endcase
104
 
105
function IsAlu0Only;
106
input [47:0] isn;
107
begin
108
case(isn[`INSTRUCTION_OP])
109
`R2:
110
        if (isn[`INSTRUCTION_L2]==2'b00)
111
                case(isn[`INSTRUCTION_S2])
112
                `R1:        IsAlu0Only = TRUE;
113
                `SHIFTR,`SHIFT31,`SHIFT63:
114 51 robfinch
                        IsAlu0Only = !(instr[25:23]==`SHL || instr[25:23]==`ASL);
115 48 robfinch
                `MULU,`MULSU,`MUL,
116 50 robfinch
                `MULUH,`MULSUH,`MULH,
117
                `MODU,`MODSU,`MOD: IsAlu0Only = TRUE;
118
                `DIVU,`DIVSU,`DIV: IsAlu0Only = TRUE;
119 48 robfinch
                `MIN,`MAX:  IsAlu0Only = TRUE;
120
                default:    IsAlu0Only = FALSE;
121
                endcase
122
        else
123
                IsAlu0Only = FALSE;
124
`MEMNDX:        IsAlu0Only = TRUE;
125
`IVECTOR,`FVECTOR:
126
        case(isn[`INSTRUCTION_S2])
127
        `VSHL,`VSHR,`VASR:  IsAlu0Only = TRUE;
128
        default: IsAlu0Only = FALSE;
129
        endcase
130
`BITFIELD:  IsAlu0Only = TRUE;
131
`MULUI,`MULI,
132
`DIVUI,`DIVI,
133
`MODI:   IsAlu0Only = TRUE;
134
`CSRRW: IsAlu0Only = TRUE;
135
default:    IsAlu0Only = FALSE;
136
endcase
137
end
138
endfunction
139
 
140
function IsFPU;
141
input [47:0] isn;
142
begin
143
case(isn[`INSTRUCTION_OP])
144
`FLOAT: IsFPU = TRUE;
145
`FVECTOR:
146
                    case(isn[`INSTRUCTION_S2])
147
            `VSHL,`VSHR,`VASR:  IsFPU = FALSE;
148
            default:    IsFPU = TRUE;
149
            endcase
150
default:    IsFPU = FALSE;
151
endcase
152
end
153
endfunction
154
 
155
reg IsFlowCtrl;
156
 
157
always @*
158
case(instr[`INSTRUCTION_OP])
159
`BRK:    IsFlowCtrl <= TRUE;
160 49 robfinch
`R2:    case(instr[`INSTRUCTION_S2])
161 48 robfinch
        `RTI:   IsFlowCtrl <= TRUE;
162
        default:    IsFlowCtrl <= FALSE;
163
        endcase
164
`Bcc:   IsFlowCtrl <= TRUE;
165
`BBc:           IsFlowCtrl <= TRUE;
166
`BEQI:  IsFlowCtrl <= TRUE;
167
`CHK:   IsFlowCtrl <= TRUE;
168
`JAL:   IsFlowCtrl <= TRUE;
169
`JMP:           IsFlowCtrl <= TRUE;
170
`CALL:  IsFlowCtrl <= TRUE;
171
`RET:   IsFlowCtrl <= TRUE;
172
default:    IsFlowCtrl <= FALSE;
173
endcase
174
 
175
//function IsFlowCtrl;
176
//input [47:0] isn;
177
//begin
178
//case(isn[`INSTRUCTION_OP])
179
//`BRK:    IsFlowCtrl = TRUE;
180
//`RR:    case(isn[`INSTRUCTION_S2])
181
//        `RTI:   IsFlowCtrl = TRUE;
182
//        default:    IsFlowCtrl = FALSE;
183
//        endcase
184
//`Bcc:   IsFlowCtrl = TRUE;
185
//`BBc:         IsFlowCtrl = TRUE;
186
//`BEQI:  IsFlowCtrl = TRUE;
187
//`CHK:   IsFlowCtrl = TRUE;
188
//`JAL:   IsFlowCtrl = TRUE;
189
//`JMP:         IsFlowCtrl = TRUE;
190
//`CALL:  IsFlowCtrl = TRUE;
191
//`RET:   IsFlowCtrl = TRUE;
192
//default:    IsFlowCtrl = FALSE;
193
//endcase
194
//end
195
//endfunction
196
 
197
// fnCanException
198
//
199
// Used by memory issue logic.
200
// Returns TRUE if the instruction can cause an exception.
201
// In debug mode any instruction could potentially cause a breakpoint exception.
202
// Rather than check all the addresses for potential debug exceptions it's
203
// simpler to just have it so that all instructions could exception. This will
204
// slow processing down somewhat as stores will only be done at the head of the
205
// instruction queue, but it's debug mode so we probably don't care.
206
//
207
function fnCanException;
208
input [47:0] isn;
209
begin
210
// ToDo add debug_on as input
211
`ifdef SUPPORT_DBG
212
if (debug_on)
213
    fnCanException = `TRUE;
214
else
215
`endif
216
case(isn[`INSTRUCTION_OP])
217
`FLOAT:
218
    case(isn[`INSTRUCTION_S2])
219
    `FDIV,`FMUL,`FADD,`FSUB,`FTX:
220
        fnCanException = `TRUE;
221
    default:    fnCanException = `FALSE;
222
    endcase
223
`ADDI,`DIVI,`MODI,`MULI:
224
    fnCanException = `TRUE;
225
`R2:
226
    case(isn[`INSTRUCTION_S2])
227 50 robfinch
    `ADD,`SUB,`MUL,
228
    `DIV,`MULSU,`DIVSU,
229
    `MOD,`MODSU:
230
       fnCanException = TRUE;
231 48 robfinch
    `RTI:   fnCanException = TRUE;
232
    default:    fnCanException = FALSE;
233
    endcase
234
`Bcc:   fnCanException = TRUE;
235
`BEQI:  fnCanException = TRUE;
236
`CHK:   fnCanException = TRUE;
237
default:
238 49 robfinch
// Stores can stil exception if there is a write buffer, but we allow following
239
// stores to be issued by ignoring the fact they can exception because the stores
240
// can be undone by invalidating the write buffer.
241
`ifdef HAS_WB
242
    fnCanException = IsLoad(isn);
243
`else
244 48 robfinch
    fnCanException = IsMem(isn);
245 49 robfinch
`endif
246 48 robfinch
endcase
247
end
248
endfunction
249
 
250
function IsLoad;
251
input [47:0] isn;
252
case(isn[`INSTRUCTION_OP])
253
`MEMNDX:
254
        if (isn[`INSTRUCTION_L2]==2'b00)
255 50 robfinch
    case(isn[`INSTRUCTION_S2])
256
    `LBX:   IsLoad = TRUE;
257
    `LBUX:  IsLoad = TRUE;
258
    `LCX:   IsLoad = TRUE;
259
    `LCUX:  IsLoad = TRUE;
260
    `LHX:   IsLoad = TRUE;
261
    `LHUX:  IsLoad = TRUE;
262
    `LWX:   IsLoad = TRUE;
263
    `LVBX:  IsLoad = TRUE;
264
    `LVBUX: IsLoad = TRUE;
265
    `LVCX:  IsLoad = TRUE;
266
    `LVCUX: IsLoad = TRUE;
267
    `LVHX:  IsLoad = TRUE;
268
    `LVHUX: IsLoad = TRUE;
269
    `LVWX:  IsLoad = TRUE;
270
    `LWRX:  IsLoad = TRUE;
271
    `LVX:   IsLoad = TRUE;
272
    default: IsLoad = FALSE;
273
    endcase
274 48 robfinch
        else
275
                IsLoad = FALSE;
276
`LB:    IsLoad = TRUE;
277
`LBU:   IsLoad = TRUE;
278
`Lx:    IsLoad = TRUE;
279
`LxU:   IsLoad = TRUE;
280
`LWR:   IsLoad = TRUE;
281
`LV:    IsLoad = TRUE;
282
`LVx:   IsLoad = TRUE;
283
default:    IsLoad = FALSE;
284
endcase
285
endfunction
286
 
287 50 robfinch
function IsVolatileLoad;
288
input [47:0] isn;
289
case(isn[`INSTRUCTION_OP])
290
`MEMNDX:
291
        if (isn[`INSTRUCTION_L2]==2'b00)
292
    case(isn[`INSTRUCTION_S2])
293
    `LWRX:      IsVolatileLoad = TRUE;
294
    `LVBX:      IsVolatileLoad = TRUE;
295
    `LVBUX:     IsVolatileLoad = TRUE;
296
    `LVCX:      IsVolatileLoad = TRUE;
297
    `LVCUX:     IsVolatileLoad = TRUE;
298
    `LVHX:      IsVolatileLoad = TRUE;
299
    `LVHUX:     IsVolatileLoad = TRUE;
300
    `LVWX:      IsVolatileLoad = TRUE;
301
    default: IsVolatileLoad = FALSE;
302
    endcase
303
        else
304
                IsVolatileLoad = FALSE;
305
`LWR:   IsVolatileLoad = TRUE;
306
`LVx:   IsVolatileLoad = TRUE;
307
default:    IsVolatileLoad = FALSE;
308
endcase
309
endfunction
310
 
311
function IsStore;
312
input [47:0] isn;
313
case(isn[`INSTRUCTION_OP])
314
`MEMNDX:
315
        if (isn[`INSTRUCTION_L2]==2'b00)
316
    case(isn[`INSTRUCTION_S2])
317
    `SBX:   IsStore = TRUE;
318
    `SCX:   IsStore = TRUE;
319
    `SHX:   IsStore = TRUE;
320
    `SWX:   IsStore = TRUE;
321
    `SWCX:  IsStore = TRUE;
322
    `SVX:   IsStore = TRUE;
323
    `CASX:  IsStore = TRUE;
324
    `INC:       IsStore = TRUE;
325
    default:    IsStore = FALSE;
326
    endcase
327
        else
328
                IsStore = FALSE;
329
`SB:    IsStore = TRUE;
330
`Sx:    IsStore = TRUE;
331
`SWC:   IsStore = TRUE;
332
`INC:   IsStore = TRUE;
333
`SV:    IsStore = TRUE;
334
`CAS:   IsStore = TRUE;
335
`AMO:   IsStore = TRUE;
336
default:    IsStore = FALSE;
337
endcase
338
endfunction
339
 
340 48 robfinch
function [0:0] IsMem;
341
input [47:0] isn;
342
case(isn[`INSTRUCTION_OP])
343
`MEMNDX:        IsMem = TRUE;
344
`AMO:           IsMem = TRUE;
345
`LB:    IsMem = TRUE;
346
`LBU:   IsMem = TRUE;
347
`Lx:    IsMem = TRUE;
348
`LxU:   IsMem = TRUE;
349
`LWR:   IsMem = TRUE;
350
`LV,`SV:    IsMem = TRUE;
351
`INC:           IsMem = TRUE;
352
`SB:    IsMem = TRUE;
353
`Sx:    IsMem = TRUE;
354
`SWC:   IsMem = TRUE;
355
`CAS:   IsMem = TRUE;
356
`LVx:           IsMem = TRUE;
357
default:    IsMem = FALSE;
358
endcase
359
endfunction
360
 
361
function IsMemNdx;
362
input [47:0] isn;
363
case(isn[`INSTRUCTION_OP])
364
`MEMNDX:        IsMemNdx = TRUE;
365
default:    IsMemNdx = FALSE;
366
endcase
367
endfunction
368
 
369 50 robfinch
function [2:0] MemSize;
370
input [47:0] isn;
371
case(isn[`INSTRUCTION_OP])
372
`MEMNDX:
373
        if (isn[`INSTRUCTION_L2]==2'b00)
374
    case(isn[`INSTRUCTION_S2])
375
    `LVBX,`LVBUX:       MemSize = byt;
376
    `LBX,`LBUX,`SBX:   MemSize = byt;
377
    `LVCX,`LVCUX:                        MemSize = wyde;
378
    `LCX,`LCUX,`SCX:   MemSize = wyde;
379
    `LVHX,`LVHUX:               MemSize = tetra;
380
    `LHX,`SHX:   MemSize = tetra;
381
    `LHUX: MemSize = tetra;
382
    `LVWX:                       MemSize = octa;
383
    `LWX,`SWX:   MemSize = octa;
384
    `LWRX,`SWCX: MemSize = octa;
385
    `LVX,`SVX:   MemSize = octa;
386
    `LVx:
387
        case(isn[25:23])
388
        3'd0,3'd1:      MemSize = byt;
389
        3'd2,3'd3:      MemSize = wyde;
390
        3'd4,3'd5:      MemSize = tetra;
391
        default:        MemSize = octa;
392
        endcase
393
    default: MemSize = octa;
394
    endcase
395
        else
396
                MemSize = octa;
397
`LB,`LBU,`SB:    MemSize = byt;
398
`Lx,`LxU,`Sx,`LVx:
399
        casez(isn[20:18])
400
        3'b100: MemSize = octa;
401
        3'b?10: MemSize = tetra;
402
        3'b??1: MemSize = wyde;
403
        default:        MemSize = octa;
404
        endcase
405
`LWR,`SWC:  MemSize = octa;
406
`LV,`SV:    MemSize = octa;
407
`AMO:
408
        case(isn[23:21])
409
        3'd0:   MemSize = byt;
410
        3'd1:   MemSize = wyde;
411
        3'd2:   MemSize = tetra;
412
        3'd3:   MemSize = octa;
413
        default:        MemSize = octa;
414
        endcase
415
default:    MemSize = octa;
416
endcase
417
endfunction
418
 
419 48 robfinch
function IsCAS;
420
input [47:0] isn;
421
case(isn[`INSTRUCTION_OP])
422
`MEMNDX:
423
        if (isn[`INSTRUCTION_L2]==2'b00)
424
            case(isn[`INSTRUCTION_S2])
425
            `CASX:   IsCAS = TRUE;
426
            default:    IsCAS = FALSE;
427
            endcase
428
        else
429
                IsCAS = FALSE;
430
`CAS:       IsCAS = TRUE;
431
default:    IsCAS = FALSE;
432
endcase
433
endfunction
434
 
435
function IsAMO;
436
input [47:0] isn;
437
case(isn[`INSTRUCTION_OP])
438
`AMO:       IsAMO = TRUE;
439
default:    IsAMO = FALSE;
440
endcase
441
endfunction
442
 
443
function IsInc;
444
input [47:0] isn;
445
case(isn[`INSTRUCTION_OP])
446
`MEMNDX:
447
        if (isn[`INSTRUCTION_L2]==2'b00)
448
                case(isn[`INSTRUCTION_S2])
449
            `INC:   IsInc = TRUE;
450
            default:    IsInc = FALSE;
451
            endcase
452
        else
453
                IsInc = FALSE;
454
`INC:    IsInc = TRUE;
455
default:    IsInc = FALSE;
456
endcase
457
endfunction
458
 
459
function IsSync;
460
input [47:0] isn;
461
IsSync = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`SYNC);
462
endfunction
463
 
464
function IsFSync;
465
input [47:0] isn;
466
IsFSync = (isn[`INSTRUCTION_OP]==`FLOAT && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`FSYNC);
467
endfunction
468
 
469
function IsMemdb;
470
input [47:0] isn;
471
IsMemdb = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMDB);
472
endfunction
473
 
474
function IsMemsb;
475
input [47:0] isn;
476
IsMemsb = (isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMSB);
477
endfunction
478
 
479
function IsSEI;
480
input [47:0] isn;
481
IsSEI = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`SEI);
482
endfunction
483
 
484
function IsShift48;
485
input [47:0] isn;
486
case(isn[`INSTRUCTION_OP])
487
`R2:
488
        if (isn[`INSTRUCTION_L2]==2'b01)
489
            case(isn[47:42])
490
            `SHIFTR: IsShift48 = TRUE;
491
            default: IsShift48 = FALSE;
492
            endcase
493
    else
494
        IsShift48 = FALSE;
495
default: IsShift48 = FALSE;
496
endcase
497
endfunction
498
 
499
function IsLWRX;
500
input [47:0] isn;
501
case(isn[`INSTRUCTION_OP])
502
`MEMNDX:
503
        if (isn[`INSTRUCTION_L2]==2'b00)
504
            case(isn[`INSTRUCTION_S2])
505
            `LWRX:   IsLWRX = TRUE;
506
            default:    IsLWRX = FALSE;
507
            endcase
508
        else
509
                IsLWRX = FALSE;
510
default:    IsLWRX = FALSE;
511
endcase
512
endfunction
513
 
514
// Aquire / release bits are only available on indexed SWC / LWR
515
function IsSWCX;
516
input [47:0] isn;
517
case(isn[`INSTRUCTION_OP])
518
`MEMNDX:
519
        if (isn[`INSTRUCTION_L2]==2'b00)
520
            case(isn[`INSTRUCTION_S2])
521
            `SWCX:   IsSWCX = TRUE;
522
            default:    IsSWCX = FALSE;
523
            endcase
524
        else
525
                IsSWCX = FALSE;
526
default:    IsSWCX = FALSE;
527
endcase
528
endfunction
529
 
530
function IsJmp;
531
input [47:0] isn;
532 51 robfinch
IsJmp = isn[`INSTRUCTION_OP]==`JMP;// && isn[7]==1'b0;
533 48 robfinch
endfunction
534
 
535
// Really IsPredictableBranch
536
// Does not include BccR's
537
function IsBranch;
538
input [47:0] isn;
539
casez(isn[`INSTRUCTION_OP])
540
`Bcc:   IsBranch = TRUE;
541
`BBc:   IsBranch = TRUE;
542
`BEQI:  IsBranch = TRUE;
543
`CHK:   IsBranch = TRUE;
544
default:    IsBranch = FALSE;
545
endcase
546
endfunction
547
 
548 51 robfinch
function IsJAL;
549
input [47:0] isn;
550
IsJAL = isn[`INSTRUCTION_OP]==`JAL;// && isn[7]==1'b0;
551
endfunction
552
 
553
function IsRet;
554
input [47:0] isn;
555
IsRet = isn[`INSTRUCTION_OP]==`RET;// && isn[7]==1'b0;
556
endfunction
557
 
558
function IsIrq;
559
input [47:0] isn;
560
IsIrq = isn[`INSTRUCTION_OP]==`BRK /*&& isn[`INSTRUCTION_L2]==2'b00*/ && isn[23:20]==4'h0;
561
endfunction
562
 
563 48 robfinch
function IsBrk;
564
input [47:0] isn;
565 51 robfinch
IsBrk = isn[`INSTRUCTION_OP]==`BRK;// && isn[`INSTRUCTION_L2]==2'b00;
566 48 robfinch
endfunction
567
 
568
function IsRti;
569
input [47:0] isn;
570 51 robfinch
IsRti = isn[`INSTRUCTION_OP]==`RR /*&& isn[`INSTRUCTION_L2]==2'b00*/ && isn[`INSTRUCTION_S2]==`RTI;
571 48 robfinch
endfunction
572
 
573
// Has an extendable 14-bit constant
574
function HasConst;
575
input [47:0] isn;
576
casez(isn[`INSTRUCTION_OP])
577
`ADDI:  HasConst = TRUE;
578
`SLTI:  HasConst = TRUE;
579
`SLTUI: HasConst = TRUE;
580
`SGTI:  HasConst = TRUE;
581
`SGTUI: HasConst = TRUE;
582
`ANDI:  HasConst = TRUE;
583
`ORI:   HasConst = TRUE;
584
`XORI:  HasConst = TRUE;
585
`XNORI: HasConst = TRUE;
586
`MULUI: HasConst = TRUE;
587
`MULI:  HasConst = TRUE;
588
`DIVUI: HasConst = TRUE;
589
`DIVI:  HasConst = TRUE;
590
`MODI:  HasConst = TRUE;
591
`LB:    HasConst = TRUE;
592
`LBU:   HasConst = TRUE;
593
`Lx:    HasConst = TRUE;
594
`LWR:           HasConst = TRUE;
595
`LV:    HasConst = TRUE;
596
`SB:    HasConst = TRUE;
597
`Sx:    HasConst = TRUE;
598
`SWC:   HasConst = TRUE;
599
`INC:           HasConst = TRUE;
600
`SV:    HasConst = TRUE;
601
`CAS:   HasConst = TRUE;
602
`JAL:   HasConst = TRUE;
603
`CALL:  HasConst = TRUE;
604
`RET:   HasConst = TRUE;
605
`LVx:           HasConst = TRUE;
606
default:    HasConst = FALSE;
607
endcase
608
endfunction
609
 
610 50 robfinch
function IsOddball;
611
input [47:0] instr;
612
//if (|iqentry_exc[head])
613
//    IsOddball = TRUE;
614
//else
615
case(instr[`INSTRUCTION_OP])
616
`BRK:   IsOddball = TRUE;
617
`IVECTOR:
618
    case(instr[`INSTRUCTION_S2])
619
    `VSxx:  IsOddball = TRUE;
620
    default:    IsOddball = FALSE;
621
    endcase
622
`RR:
623
    case(instr[`INSTRUCTION_S2])
624
    `VMOV:  IsOddball = TRUE;
625
    `SEI,`RTI: IsOddball = TRUE;
626
    default:    IsOddball = FALSE;
627
    endcase
628
`MEMNDX:
629
    case(instr[`INSTRUCTION_S2])
630
    `CACHEX: IsOddball = TRUE;
631
    default:    IsOddball = FALSE;
632
    endcase
633
`CSRRW,`REX,`CACHE,`FLOAT:  IsOddball = TRUE;
634
default:    IsOddball = FALSE;
635
endcase
636
endfunction
637
 
638 48 robfinch
function IsRFW;
639
input [47:0] isn;
640
casez(isn[`INSTRUCTION_OP])
641
`IVECTOR:   IsRFW = TRUE;
642
`FVECTOR:   IsRFW = TRUE;
643
`R2:
644
        if (isn[`INSTRUCTION_L2]==2'b00)
645 50 robfinch
    case(isn[`INSTRUCTION_S2])
646
    `R1:    IsRFW = TRUE;
647
    `ADD:   IsRFW = TRUE;
648
    `SUB:   IsRFW = TRUE;
649
    `SLT:   IsRFW = TRUE;
650
    `SLTU:  IsRFW = TRUE;
651
    `SLE:   IsRFW = TRUE;
652
    `SLEU:  IsRFW = TRUE;
653
    `AND:   IsRFW = TRUE;
654
    `OR:    IsRFW = TRUE;
655
    `XOR:   IsRFW = TRUE;
656
    `MULU:  IsRFW = TRUE;
657
    `MULSU: IsRFW = TRUE;
658
    `MUL:   IsRFW = TRUE;
659
    `MULUH:  IsRFW = TRUE;
660
    `MULSUH: IsRFW = TRUE;
661
    `MULH:   IsRFW = TRUE;
662
    `DIVU:  IsRFW = TRUE;
663
    `DIVSU: IsRFW = TRUE;
664
    `DIV:IsRFW = TRUE;
665
    `MODU:  IsRFW = TRUE;
666
    `MODSU: IsRFW = TRUE;
667
    `MOD:IsRFW = TRUE;
668
    `MOV:       IsRFW = TRUE;
669
    `VMOV:      IsRFW = TRUE;
670
    `SHIFTR,`SHIFT31,`SHIFT63:
671
                IsRFW = TRUE;
672
    `MIN,`MAX:    IsRFW = TRUE;
673
    `SEI:       IsRFW = TRUE;
674
    default:    IsRFW = FALSE;
675
    endcase
676 48 robfinch
        else
677
                IsRFW = FALSE;
678
`MEMNDX:
679
        if (isn[`INSTRUCTION_L2]==2'b00)
680 50 robfinch
    case(isn[`INSTRUCTION_S2])
681
    `LBX:   IsRFW = TRUE;
682
    `LBUX:  IsRFW = TRUE;
683
    `LCX:   IsRFW = TRUE;
684
    `LCUX:  IsRFW = TRUE;
685
    `LHX:   IsRFW = TRUE;
686
    `LHUX:  IsRFW = TRUE;
687
    `LWX:   IsRFW = TRUE;
688
    `LVBX:  IsRFW = TRUE;
689
    `LVBUX: IsRFW = TRUE;
690
    `LVCX:  IsRFW = TRUE;
691
    `LVCUX: IsRFW = TRUE;
692
    `LVHX:  IsRFW = TRUE;
693
    `LVHUX: IsRFW = TRUE;
694
    `LVWX:  IsRFW = TRUE;
695
    `LWX:   IsRFW = TRUE;
696
    `LWRX:  IsRFW = TRUE;
697
    `LVX:   IsRFW = TRUE;
698
    `CASX:  IsRFW = TRUE;
699
    default:    IsRFW = FALSE;
700
    endcase
701 48 robfinch
        else
702
                IsRFW = FALSE;
703
`BBc:
704
        case(isn[20:19])
705
        `IBNE:  IsRFW = TRUE;
706
        `DBNZ:  IsRFW = TRUE;
707
        default:        IsRFW = FALSE;
708
        endcase
709
`BITFIELD:  IsRFW = TRUE;
710
`ADDI:      IsRFW = TRUE;
711
`SLTI:      IsRFW = TRUE;
712
`SLTUI:     IsRFW = TRUE;
713
`SGTI:      IsRFW = TRUE;
714
`SGTUI:     IsRFW = TRUE;
715
`ANDI:      IsRFW = TRUE;
716
`ORI:       IsRFW = TRUE;
717
`XORI:      IsRFW = TRUE;
718
`MULUI:     IsRFW = TRUE;
719
`MULI:      IsRFW = TRUE;
720
`DIVUI:     IsRFW = TRUE;
721
`DIVI:      IsRFW = TRUE;
722
`MODI:      IsRFW = TRUE;
723
`JAL:       IsRFW = TRUE;
724
`CALL:      IsRFW = TRUE;
725
`RET:       IsRFW = TRUE;
726
`LB:        IsRFW = TRUE;
727
`LBU:       IsRFW = TRUE;
728
`Lx:        IsRFW = TRUE;
729
`LWR:       IsRFW = TRUE;
730
`LV:        IsRFW = TRUE;
731
`LVx:                           IsRFW = TRUE;
732
`CAS:       IsRFW = TRUE;
733
`AMO:                           IsRFW = TRUE;
734
`CSRRW:                 IsRFW = TRUE;
735
default:    IsRFW = FALSE;
736
endcase
737
endfunction
738
 
739
// Determines which lanes of the target register get updated.
740
function [7:0] fnWe;
741
input [47:0] isn;
742
casez(isn[`INSTRUCTION_OP])
743
`R2:
744
        case(isn[`INSTRUCTION_S2])
745
        `R1:
746
                case(isn[22:18])
747
                `ABS,`CNTLZ,`CNTLO,`CNTPOP:
748
                        case(isn[25:23])
749
                        3'b000: fnWe = 8'h01;
750
                        3'b001: fnWe = 8'h03;
751
                        3'b010: fnWe = 8'h0F;
752
                        3'b011: fnWe = 8'hFF;
753
                        default:        fnWe = 8'hFF;
754
                        endcase
755
                default: fnWe = 8'hFF;
756
                endcase
757
        `SHIFT31:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
758
        `SHIFT63:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
759
        `SLT,`SLTU,`SLE,`SLEU,
760
        `ADD,`SUB,
761
        `AND,`OR,`XOR,
762
        `NAND,`NOR,`XNOR,
763 50 robfinch
        `DIV,`DIVU,`DIVSU,
764
        `MOD,`MODU,`MODSU,
765
        `MUL,`MULU,`MULSU,
766
        `MULH,`MULUH,`MULSUH:
767 48 robfinch
                case(isn[25:23])
768
                3'b000: fnWe = 8'h01;
769
                3'b001: fnWe = 8'h03;
770
                3'b010: fnWe = 8'h0F;
771
                3'b011: fnWe = 8'hFF;
772
                default:        fnWe = 8'hFF;
773
                endcase
774
        default: fnWe = 8'hFF;
775
        endcase
776
default:        fnWe = 8'hFF;
777
endcase
778
endfunction
779
 
780
// Detect if a source is automatically valid
781
function Source1Valid;
782
input [47:0] isn;
783
casez(isn[`INSTRUCTION_OP])
784
`BRK:   Source1Valid = TRUE;
785
`Bcc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
786
`BBc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
787
`BEQI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
788
`CHK:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
789
`R2:    case(isn[`INSTRUCTION_S2])
790
        `SHIFT31:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
791
        `SHIFT63:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
792
        `SHIFTR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
793
        default:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
794
        endcase
795
`MEMNDX:        Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
796
`ADDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
797
`SLTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
798
`SLTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
799
`SGTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
800
`SGTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
801
`ANDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
802
`ORI:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
803
`XORI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
804
`XNORI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
805
`MULUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
806
`AMO:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
807
`LB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
808
`LBU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
809
`Lx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
810
`LxU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
811
`LWR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
812
`LV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
813
`LVx:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
814
`SB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
815
`Sx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
816
`SWC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
817
`SV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
818
`INC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
819
`CAS:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
820
`JAL:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
821
`RET:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
822
`CSRRW: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
823
`BITFIELD:      case(isn[31:28])
824
                        `BFINSI:        Source1Valid = TRUE;
825
                        default:        Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
826
                        endcase
827
`IVECTOR:
828
                        Source1Valid = FALSE;
829
default:    Source1Valid = TRUE;
830
endcase
831
endfunction
832
 
833
function Source2Valid;
834
input [47:0] isn;
835
casez(isn[`INSTRUCTION_OP])
836
`BRK:   Source2Valid = TRUE;
837
`Bcc:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
838
`BBc:   Source2Valid = TRUE;
839
`BEQI:  Source2Valid = TRUE;
840
`CHK:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
841
`R2:    case(isn[`INSTRUCTION_S2])
842
        `R1:       Source2Valid = TRUE;
843
        `SHIFTR:   Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
844
        `SHIFT31:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
845
        `SHIFT63:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
846
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
847
        endcase
848
`MEMNDX: case(isn[`INSTRUCTION_S2])
849
        `LVX,`SVX: Source2Valid = FALSE;
850
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
851
        endcase
852
`ADDI:  Source2Valid = TRUE;
853
`SLTI:  Source2Valid = TRUE;
854
`SLTUI: Source2Valid = TRUE;
855
`SGTI:  Source2Valid = TRUE;
856
`SGTUI: Source2Valid = TRUE;
857
`ANDI:  Source2Valid = TRUE;
858
`ORI:   Source2Valid = TRUE;
859
`XORI:  Source2Valid = TRUE;
860
`XNORI: Source2Valid = TRUE;
861
`MULUI: Source2Valid = TRUE;
862
`LB:    Source2Valid = TRUE;
863
`LBU:   Source2Valid = TRUE;
864
`Lx:    Source2Valid = TRUE;
865
`LxU:   Source2Valid = TRUE;
866
`LWR:   Source2Valid = TRUE;
867
`LVx:   Source2Valid = TRUE;
868
`INC:           Source2Valid = TRUE;
869
`SB:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
870
`Sx:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
871
`SWC:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
872
`CAS:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
873
`JAL:   Source2Valid = TRUE;
874
`RET:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
875
`IVECTOR:
876
                    case(isn[`INSTRUCTION_S2])
877
            `VABS:  Source2Valid = TRUE;
878
            `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
879
                Source2Valid = FALSE;
880
            `VADDS,`VSUBS,`VANDS,`VORS,`VXORS:
881
                Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
882
            `VBITS2V:   Source2Valid = TRUE;
883
            `V2BITS:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
884
            `VSHL,`VSHR,`VASR:  Source2Valid = isn[22:21]==2'd2;
885
            default:    Source2Valid = FALSE;
886
            endcase
887
`LV:        Source2Valid = TRUE;
888
`SV:        Source2Valid = FALSE;
889
`AMO:           Source2Valid = isn[31] || isn[`INSTRUCTION_RB]==5'd0;
890
default:    Source2Valid = TRUE;
891
endcase
892
endfunction
893
 
894
function Source3Valid;
895
input [47:0] isn;
896
case(isn[`INSTRUCTION_OP])
897
`IVECTOR:
898
    case(isn[`INSTRUCTION_S2])
899
    `VEX:       Source3Valid = TRUE;
900
    default:    Source3Valid = TRUE;
901
    endcase
902
`CHK:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
903
`R2:
904
        if (isn[`INSTRUCTION_L2]==2'b01)
905
                case(isn[47:42])
906
    `CMOVEZ,`CMOVNZ:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
907
                default:        Source3Valid = TRUE;
908
                endcase
909
        else
910
    case(isn[`INSTRUCTION_S2])
911
    `MAJ:               Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
912
    default:    Source3Valid = TRUE;
913
    endcase
914
`MEMNDX:
915
        if (isn[`INSTRUCTION_L2]==2'b00)
916
    case(isn[`INSTRUCTION_S2])
917
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
918
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
919
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
920
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
921
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
922
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
923
    default:    Source3Valid = TRUE;
924
    endcase
925
default:    Source3Valid = TRUE;
926
endcase
927
endfunction
928
 
929
always @(posedge clk)
930
begin
931 51 robfinch
        bus <= 144'h0;
932
        bus[`IB_CONST] <= instr[6]==1'b1 ? {{34{instr[47]}},instr[47:18]} :
933
                                                                                                                                                        {{50{instr[31]}},instr[31:18]};
934 48 robfinch
        case(instr[7:6])
935
        2'b00:  bus[`IB_LN] <= 3'd4;
936
        2'b01:  bus[`IB_LN] <= 3'd6;
937
        default: bus[`IB_LN] <= 3'd2;
938
        endcase
939
//      bus[`IB_RT]              <= fnRt(instr,ven,vl,thrd) | {thrd,7'b0};
940
//      bus[`IB_RC]              <= fnRc(instr,ven,thrd) | {thrd,7'b0};
941
//      bus[`IB_RA]              <= fnRa(instr,ven,vl,thrd) | {thrd,7'b0};
942
        bus[`IB_IMM]     <= HasConst(instr);
943 50 robfinch
//      bus[`IB_A3V]   <= Source3Valid(instr);
944
//      bus[`IB_A2V]   <= Source2Valid(instr);
945
//      bus[`IB_A1V]   <= Source1Valid(instr);
946 51 robfinch
        bus[`IB_IRQ]     <= IsIrq(instr);
947
        bus[`IB_BRK]     <= IsBrk(instr);
948
        bus[`IB_RTI]     <= IsRti(instr);
949
        bus[`IB_RET]     <= IsRet(instr);
950
        bus[`IB_JAL]     <= IsJAL(instr);
951 48 robfinch
        bus[`IB_BT]    <= (IsBranch(instr) && predict_taken);
952
        bus[`IB_ALU]   <= IsALU;
953
        bus[`IB_ALU0]  <= IsAlu0Only(instr);
954
        bus[`IB_FPU]   <= IsFPU(instr);
955
        bus[`IB_FC]              <= IsFlowCtrl;
956
        bus[`IB_CANEX] <= fnCanException(instr);
957 50 robfinch
        bus[`IB_LOADV] <= IsVolatileLoad(instr);
958 48 robfinch
        bus[`IB_LOAD]    <= IsLoad(instr);
959
        bus[`IB_PRELOAD] <=   IsLoad(instr) && Rt==5'd0;
960 50 robfinch
        bus[`IB_STORE]  <= IsStore(instr);
961
        bus[`IB_ODDBALL] <= IsOddball(instr);
962
        bus[`IB_MEMSZ]  <= MemSize(instr);
963 48 robfinch
        bus[`IB_MEM]            <= IsMem(instr);
964
        bus[`IB_MEMNDX] <= IsMemNdx(instr);
965
        bus[`IB_RMW]            <= IsCAS(instr) || IsAMO(instr) || IsInc(instr);
966
        bus[`IB_MEMDB]  <= IsMemdb(instr);
967
        bus[`IB_MEMSB]  <= IsMemsb(instr);
968
        bus[`IB_SHFT48] <= IsShift48(instr);
969
        bus[`IB_SEI]            <= IsSEI(instr);
970
        bus[`IB_AQ]                     <= (IsAMO(instr)|IsLWRX(instr)|IsSWCX(instr)) & instr[25];
971
        bus[`IB_RL]                     <= (IsAMO(instr)|IsLWRX(instr)|IsSWCX(instr)) & instr[24];
972
        bus[`IB_JMP]            <= IsJmp(instr);
973
        bus[`IB_BR]                     <= IsBranch(instr);
974
        bus[`IB_SYNC]           <= IsSync(instr)||IsBrk(instr)||IsRti(instr);
975
        bus[`IB_FSYNC]  <= IsFSync(instr);
976
        bus[`IB_RFW]            <= Rt==5'd0 ? 1'b0 : IsRFW(instr);
977
        bus[`IB_WE]                     <= fnWe(instr);
978
        id_o <= id_i;
979
        idv_o <= idv_i;
980
end
981
 
982
endmodule
983
 
984
module mIsALU(instr, IsALU);
985
input [47:0] instr;
986
output reg IsALU;
987
parameter TRUE = 1'b1;
988
parameter FALSE = 1'b0;
989
 
990
always @*
991
casez(instr[`INSTRUCTION_OP])
992 50 robfinch
`R2:
993
  if (instr[`INSTRUCTION_L2]==2'b00)
994
                case(instr[`INSTRUCTION_S2])
995
                `VMOV:          IsALU = TRUE;
996
    `RTI:       IsALU = FALSE;
997
    default:    IsALU = TRUE;
998
    endcase
999
    else
1000
        IsALU = TRUE;
1001 48 robfinch
`BRK:   IsALU = FALSE;
1002
`Bcc:   IsALU = FALSE;
1003
`BBc:   IsALU = FALSE;
1004
`BEQI:  IsALU = FALSE;
1005
`CHK:   IsALU = FALSE;
1006
`JAL:   IsALU = FALSE;
1007
`JMP:   IsALU = FALSE;
1008
`CALL:  IsALU = FALSE;
1009
`RET:   IsALU = FALSE;
1010
`FVECTOR:
1011 50 robfinch
        case(instr[`INSTRUCTION_S2])
1012
  `VSHL,`VSHR,`VASR:  IsALU = TRUE;
1013
  default:    IsALU = FALSE;  // Integer
1014
  endcase
1015 48 robfinch
`IVECTOR:
1016 50 robfinch
        case(instr[`INSTRUCTION_S2])
1017
  `VSHL,`VSHR,`VASR:  IsALU = TRUE;
1018
  default:    IsALU = TRUE;  // Integer
1019
  endcase
1020 48 robfinch
`FLOAT:         IsALU = FALSE;
1021
default:    IsALU = TRUE;
1022
endcase
1023
 
1024
endmodule

powered by: WebSVN 2.1.0

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