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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [beta_2.0/] [rtl/] [Module_InstructionIssue.v] - Blame information for rev 230

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 213 diegovalve
`include "aDefinitions.v"
2
 
3
/**********************************************************************************
4
Theia, Ray Cast Programable graphic Processing Unit.
5
Copyright (C) 2012  Diego Valverde (diego.valverde.g@gmail.com)
6
 
7
This program is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License
9
as published by the Free Software Foundation; either version 2
10
of the License, or (at your option) any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 
21
***********************************************************************************/
22
 
23
//`define ADDRESSING_MODES_DISABLED 1
24
//`define NO_STALL_ON_BRANCH_DEPS 1
25
 
26
`define II_STATE_AFTER_RESET             0
27
`define II_FETCH_INSTRUCTION             1
28
`define II_ISSUE_REQUEST_WITH_DATA_FWD   2
29
`define II_ISSUE_REQUEST                 3
30
`define II_FIFO_UPDATE                   4
31
`define II_ISSUE_BRANCH_OPERATION        5
32
`define II_UPDATE_PC_BRANCH_OPERATION    6
33
 
34
`define TAGMEM_OWNER_ISSUE      1'b0
35
`define TAGMEM_OWNER_FIFO       1'b1
36
 
37
module InstructionIssue
38
(
39
   input wire                                   Clock,
40
        input wire                                   Reset,
41
        input wire                                   iEnable,
42
        input wire [`INSTRUCTION_WIDTH-1:0]          iInstruction0,        //Instruction fetched from IM
43
        input wire [`INSTRUCTION_WIDTH-1:0]          iInstruction1,                       //Branch taken instruction prefetch
44
        input wire [`DATA_ROW_WIDTH-1:0]             iSourceData0,         //Source0 value from RF
45
        input wire [`DATA_ROW_WIDTH-1:0]             iSourceData1,         //Source1 value from RF
46
        input wire [`NUMBER_OF_RSVR_STATIONS-1:0]    iRStationBusy,
47
        input wire [`COMMIT_PACKET_SIZE-1:0]         iResultBcast,         //Contains DST and RsId from last commited operation
48
        input wire                                   iSignFlag,
49
        input wire                                   iZeroFlag,
50
        input wire                                   iMtEnabled,
51
        input wire                                   iIgnoreResultBcast,
52
        output wire [`DATA_ADDRESS_WIDTH-1:0]        oSourceAddress0,
53
        output wire [`DATA_ADDRESS_WIDTH-1:0]        oSourceAddress1,
54
        output wire  [`ISSUE_PACKET_SIZE-1:0]        oIssueBcast,
55
   input wire [`DATA_ADDRESS_WIDTH -1:0]        iFrameOffset,iIndexRegister,
56
        input wire [`INSTRUCTION_ADDR_WIDTH-1:0]     iCodeOffset,
57
        output wire  [`INSTRUCTION_ADDR_WIDTH -1:0]  oIP0,
58
        output wire  [`INSTRUCTION_ADDR_WIDTH -1:0]  oIP1
59
 
60
);
61
 
62
 
63
parameter  SB_ENTRY_WIDTH = 4;
64
 
65
wire[SB_ENTRY_WIDTH-1:0]                wSource0_Station;     //Reservation Station that is currently calculationg Source0, zero means none
66
wire[SB_ENTRY_WIDTH-1:0]                wSource1_Station;     //Reservation Station that is currently calculationg Source1, zero means none
67
wire[SB_ENTRY_WIDTH-1:0]                wSource0_RsSb;
68
wire[`DATA_ADDRESS_WIDTH-1:0]           wSBWriteAddress;
69
wire [SB_ENTRY_WIDTH-1:0]               wSBWriteData;
70
wire                                    wStall;
71
wire [`DATA_ROW_WIDTH-1:0]              wSourceData0;
72
wire [`DATA_ROW_WIDTH-1:0]              wSourceData1;
73
wire                                    wFIFO_ReadEnable;
74
wire [`DATA_ADDRESS_WIDTH-1:0]          wFIFO_Dst;
75
wire [`DATA_ADDRESS_WIDTH-1:0]          wIssue_Dst;
76
wire [`DATA_ADDRESS_WIDTH-1:0]          wSource0Addr_Displaced,wSourceAddress0_Imm,wSource0Addr_Displaced_plus_Index;
77
wire [`DATA_ADDRESS_WIDTH-1:0]          wSource1Addr_Displaced,wSourceAddress1_Imm,wSource1Addr_Displaced_plus_Index;
78
wire                                    wSBWriteEnable;
79
wire[`DATA_ROW_WIDTH-1:0]               wSignedSourceData0;
80
wire[`DATA_ROW_WIDTH-1:0]               wSignedSourceData1;
81
wire[`DATA_ROW_WIDTH-1:0]               wSwizzledSourceData0;
82
wire[`DATA_ROW_WIDTH-1:0]               wSwizzledSourceData1;
83
wire [`DATA_ROW_WIDTH-1:0]              wResultData;
84
wire [`DATA_ROW_WIDTH-1:0]              wSourceData1Temp;
85
wire [`DATA_ROW_WIDTH-1:0]              wScaledSourceData0;
86
wire [`DATA_ROW_WIDTH-1:0]              wScaledSourceData1;
87
wire [`DATA_ROW_WIDTH-1:0]              wScaledSourceData0_Pre;
88
wire [`DATA_ROW_WIDTH-1:0]              wScaledSourceData1_Pre;
89
wire [`DATA_ROW_WIDTH-1:0]              wUnscaleSourceData0_Pre;
90
wire [`DATA_ROW_WIDTH-1:0]              wUnscaleSourceData1_Pre;
91
wire [6:0] wOp;
92
wire wBranchTaken;
93
wire wCommitBusInputFifo_Empty;
94
wire wCommitBusDataAvailabe;
95
wire wReservationStationBusy;
96
wire [`COMMIT_PACKET_SIZE-1:0] wResultFifoData;
97
reg rTagMemoryWE,rTagMemOwner,rIssueNow,rIncrementPC,rPopFifo,rBypassFifo,rUseForwardedData;
98
reg rSetPCBranchTaken;
99
wire wBranchWithDependency;
100 230 diegovalve
wire wIO_Operation_TMWRITE;
101 213 diegovalve
 
102 230 diegovalve
 
103
 
104 213 diegovalve
wire wMtHasOnceMoreTimeSlot,wEnabled_Delay;
105
wire wIO_Operation;
106 230 diegovalve
assign wIO_Operation = (~wOp[0] &  wOp[1] & wOp[2] & ~wOp[3]);
107 213 diegovalve
 
108 230 diegovalve
assign  wIO_Operation_TMWRITE = wIO_Operation && (iInstruction0[`INST_SCOP_RNG] == `IO_OPERATION_OMWRITE);
109
 
110 213 diegovalve
FFD_POSEDGE_SYNCRONOUS_RESET # ( 1 ) FFD123
111
(       Clock, Reset, 1'b1 , iEnable , wEnabled_Delay  );
112
 
113
assign wMtHasOnceMoreTimeSlot = ~wEnabled_Delay;
114
 
115
assign wStall = iInstruction0[`INST_EOF_RNG];
116
 
117
reg [4:0]  rCurrentState, rNextState;
118
//Next states logic and Reset sequence
119
always @(posedge Clock )
120
  begin
121
 
122
    if (Reset )
123
                rCurrentState <= `II_STATE_AFTER_RESET;
124
    else
125
                rCurrentState <= rNextState;
126
 
127
end
128
 
129
 
130
 
131
 
132
always @ ( * )
133
begin
134
        case (rCurrentState)
135
        //--------------------------------------
136
        `II_STATE_AFTER_RESET:
137
        begin
138
           rTagMemoryWE   = 1'b0;
139
                rTagMemOwner   = 1'b0;
140
                rIssueNow      = 1'b0;
141
                rIncrementPC   = 1'b0;
142
                rPopFifo       = 1'b0;
143
                rBypassFifo    = 1'b0;
144
                rUseForwardedData  = 1'b0;
145
                rSetPCBranchTaken  = 1'b0;
146
 
147
                rNextState = `II_FETCH_INSTRUCTION;
148
        end
149
        //--------------------------------------
150
        /*The PC will be incremented except for the scenario where we need to wait
151
        for reservation stations to become available. If we increment the PC, then the
152
        value of PC will get update the next clock cycle, and another clock cycle
153
        after that the instruction will get updated.
154
        1- If there is data waiting on the commit bus input port this cycle,
155 230 diegovalve
        then do not queue this data into the input FIFO but instead set
156 213 diegovalve
        set the score board write enable to 1, set the wSBWriteAddress
157
        to the CommitPacket Destination range   and update the score board
158
        bit to zero, so than in the next state the score board bit associated
159
        to the commit data has been updated.
160
        2 - If there is no data waiting on the commit bus this clock cycle, but there
161
        is data that has been queued into the input FIFO, then go to a state where this
162
        data status on the scoreboard gets updated.
163
        3 - If there are no available reservation stations left to handle this
164
        instruction (structural hazard) then just stay in these same state to wait for
165
        a reservation station to become availabe.
166
        */
167
        `II_FETCH_INSTRUCTION:
168
        begin
169
                rTagMemoryWE   = wCommitBusDataAvailabe;
170
                rTagMemOwner   = `TAGMEM_OWNER_ISSUE;
171
                rIssueNow      = 1'b0;
172
                rIncrementPC   =  (( ~wReservationStationBusy & ~iInstruction0[`INST_BRANCH_BIT] & wCommitBusInputFifo_Empty) | (~wReservationStationBusy & ~iInstruction0[`INST_BRANCH_BIT] & wCommitBusDataAvailabe));
173
                rPopFifo       = 1'b0;
174
                rBypassFifo    = wCommitBusDataAvailabe;                        //Write iCommitBus data directly into tag mem
175
                rUseForwardedData  = 1'b0;
176
                rSetPCBranchTaken  = 1'b0;
177
 
178
                if (wCommitBusDataAvailabe & ~wReservationStationBusy /**/& (iMtEnabled & wMtHasOnceMoreTimeSlot | ~iMtEnabled)/**/)
179
                        rNextState = `II_ISSUE_REQUEST_WITH_DATA_FWD;
180
                else if (~wCommitBusInputFifo_Empty)
181
                        rNextState = `II_FIFO_UPDATE;
182 230 diegovalve
                else if ( wReservationStationBusy | (iMtEnabled & ~wMtHasOnceMoreTimeSlot) /*| wIOWrite_Waiting_for_OMRead*/ )
183 213 diegovalve
                        rNextState = `II_FETCH_INSTRUCTION;
184
                else
185
                        rNextState = `II_ISSUE_REQUEST;
186
 
187
        end
188
                //--------------------------------------
189
                //TODO: If the reservation station is Busy (static hazard)
190
                //Then we shall stall the machine...
191
        `II_ISSUE_REQUEST:
192
        begin
193 230 diegovalve
                rTagMemoryWE   = ~iInstruction0[`INST_BRANCH_BIT] & ~wIO_Operation_TMWRITE;
194 213 diegovalve
                rTagMemOwner   = `TAGMEM_OWNER_ISSUE;
195
                rIssueNow      = iEnable;
196
                rIncrementPC   = (iInstruction0[`INST_BRANCH_BIT] & ~wBranchWithDependency & iEnable);
197
                rPopFifo       = 1'b0;
198
                rBypassFifo    = 1'b0;
199
                rUseForwardedData  = 1'b0;
200
                rSetPCBranchTaken  = 1'b0;
201
 
202
                if (~iEnable & ~wCommitBusInputFifo_Empty)
203
                        rNextState = `II_FIFO_UPDATE;
204
                else if (~iEnable & wCommitBusInputFifo_Empty)
205
                        rNextState = `II_ISSUE_REQUEST;///////////////////
206
                else
207
                if (iInstruction0[`INST_BRANCH_BIT])
208
                        rNextState = `II_UPDATE_PC_BRANCH_OPERATION;
209
                else
210
                   rNextState = `II_FETCH_INSTRUCTION;
211
        end
212
        //--------------------------------------
213
        /*
214
        Here the instruction remains the same as in the
215
        previous clock cycle.
216
        */
217
        `II_ISSUE_REQUEST_WITH_DATA_FWD:
218
        begin
219 230 diegovalve
                rTagMemoryWE   = ~iInstruction0[`INST_BRANCH_BIT] & ~wIO_Operation_TMWRITE;
220 213 diegovalve
                rTagMemOwner   = `TAGMEM_OWNER_ISSUE;
221
                rIssueNow      = iEnable;
222
                rIncrementPC   = (iInstruction0[`INST_BRANCH_BIT] & ~wBranchWithDependency & iEnable);
223
                rPopFifo       = 1'b1;
224
                rBypassFifo    = 1'b0;
225
                rUseForwardedData  = 1'b1;
226
                rSetPCBranchTaken  = 1'b0;//wBranchTaken;
227
 
228
                if (~iEnable & ~wCommitBusInputFifo_Empty)
229
                        rNextState = `II_FIFO_UPDATE;
230
                else if (~iEnable & wCommitBusInputFifo_Empty)
231
                        rNextState = `II_ISSUE_REQUEST_WITH_DATA_FWD;
232
                else
233
                if (iInstruction0[`INST_BRANCH_BIT])
234
                        rNextState = `II_UPDATE_PC_BRANCH_OPERATION;
235
                else
236
                   rNextState = `II_FETCH_INSTRUCTION;
237
        end
238
        //--------------------------------------
239
        `II_FIFO_UPDATE:
240
        begin
241
                rTagMemoryWE   = 1'b1;
242
                rTagMemOwner   = `TAGMEM_OWNER_FIFO;
243
                rIssueNow      = 1'b0;
244
                rIncrementPC   = (iMtEnabled & wMtHasOnceMoreTimeSlot /*| ~iMtEnabled*/) & ~wBranchWithDependency & (( ~wReservationStationBusy & ~iInstruction0[`INST_BRANCH_BIT]));//1'b0;
245
                rPopFifo       = 1'b1;
246
                rBypassFifo    = 1'b0;
247
                rUseForwardedData  = 1'b0;
248
                rSetPCBranchTaken  = 1'b0;
249
 
250
                if (wBranchWithDependency & ~iMtEnabled)
251
                        rNextState = `II_UPDATE_PC_BRANCH_OPERATION;
252
                else if ((~iMtEnabled | (iMtEnabled & wMtHasOnceMoreTimeSlot)) & ~wBranchWithDependency & (( ~wReservationStationBusy & ~iInstruction0[`INST_BRANCH_BIT])))
253
                        rNextState = `II_ISSUE_REQUEST;
254
                else
255
                        rNextState = `II_FETCH_INSTRUCTION;
256
        end
257
        //--------------------------------------
258
        //FIXME: You are assuming that the branch takes 1 cycle.
259
        //This may noy always be the case..
260
        `II_UPDATE_PC_BRANCH_OPERATION:
261
        begin
262
                rTagMemoryWE   = 1'b0;
263
                rTagMemOwner   = `TAGMEM_OWNER_FIFO;
264
                rIssueNow      = 1'b0;
265
                rIncrementPC   = 1'b0;
266
                rPopFifo       = 1'b1;
267
                rBypassFifo    = 1'b0;
268
                rUseForwardedData  = 1'b0;
269
                rSetPCBranchTaken  = wBranchTaken;
270
 
271
`ifdef NO_STALL_ON_BRANCH_DEPS
272
                rNextState = `II_FETCH_INSTRUCTION;
273
`else
274
                if (~wBranchWithDependency)
275
                        rNextState = `II_FETCH_INSTRUCTION;
276
                else if (~wCommitBusInputFifo_Empty)
277
                        rNextState = `II_FIFO_UPDATE;
278
                else
279
                        rNextState = `II_UPDATE_PC_BRANCH_OPERATION;
280
`endif
281
 
282
 
283
        end
284
        //--------------------------------------
285
        default:
286
        begin
287
                rTagMemOwner   = `TAGMEM_OWNER_ISSUE;
288
           rTagMemoryWE   = 1'b0;
289
                rIssueNow      = 1'b0;
290
                rIncrementPC   = 1'b0;
291
                rPopFifo       = 1'b0;
292
                rBypassFifo    = 1'b0;
293
                rUseForwardedData  = 1'b0;
294
                rSetPCBranchTaken  = 1'b0;
295
 
296
                rNextState = `II_STATE_AFTER_RESET;
297
        end
298
        //--------------------------------------
299
        endcase
300
 
301
 
302
end
303
 
304
wire [2:0] wInstructionBranchSelection;
305
assign wInstructionBranchSelection = iInstruction0[`INST_BRANCH_OP_RNG];
306
wire wCommitFromPendingStation;
307
assign wCommitFromPendingStation = (iResultBcast[`COMMIT_RSID_RNG] == wReservationStation) ? 1'b1 : 1'b0;
308
 
309
assign wBranchTaken =
310
wCommitFromPendingStation &
311
iInstruction0[`INST_BRANCH_BIT] &
312
(
313
~wInstructionBranchSelection[2] & ~wInstructionBranchSelection[1] & ~wInstructionBranchSelection[0] |                          //inconditional BRANCH  
314
~wInstructionBranchSelection[2] & ~wInstructionBranchSelection[1] & wInstructionBranchSelection[0] & iZeroFlag |                 //==
315
~wInstructionBranchSelection[2] & wInstructionBranchSelection[1] & ~wInstructionBranchSelection[0] & ~iZeroFlag |                //!=
316
~wInstructionBranchSelection[2] & wInstructionBranchSelection[1] & wInstructionBranchSelection[0] & iSignFlag |                  //<
317
wInstructionBranchSelection[2] & ~wInstructionBranchSelection[1] & ~wInstructionBranchSelection[0] & (~iSignFlag & ~iZeroFlag)|  //>
318
wInstructionBranchSelection[2] & ~wInstructionBranchSelection[1] & wInstructionBranchSelection[0] & (iSignFlag | iZeroFlag) |    //<=
319
wInstructionBranchSelection[2] & wInstructionBranchSelection[1] & ~wInstructionBranchSelection[0] & (~iSignFlag | iZeroFlag)     //>=
320
);
321
 
322
wire [`COMMIT_PACKET_SIZE-1:0] wCommitData_Latched;
323
FFD_POSEDGE_SYNCRONOUS_RESET # ( `COMMIT_PACKET_SIZE ) ICOMMIT_BYPASS_FFD
324
(       Clock, Reset, 1'b1 ,iResultBcast  , wCommitData_Latched  );
325
 
326
 
327
//The Reservation Station scoreboard
328
wire [SB_ENTRY_WIDTH-1:0] wSBDataPort0;
329
wire [SB_ENTRY_WIDTH-1:0] wSBDataPort1;
330
wire[3:0] wReservationStation;
331
 
332
 `ifdef ADDRESSING_MODES_DISABLED
333 230 diegovalve
 
334
 //There a two possible ways to update the Score board. The SB can be update by the operation we just commited: iInstruction0
335
 //or the SB can be updated by the value comming from the wResultFifoData
336 213 diegovalve
assign wSBWriteAddress
337
 = (rTagMemOwner == `TAGMEM_OWNER_ISSUE) ? ((rBypassFifo)?iResultBcast[`COMMIT_DST_RNG]:iInstruction0[`INST_DST_RNG])
338
 : wResultFifoData[`COMMIT_DST_RNG];
339
 
340
 `else
341 230 diegovalve
 //There a two possible ways to update the Score board. The SB can be update by the operation we just commited: iInstruction0
342
 //or the SB can be updated by the value comming from the wResultFifoData
343 213 diegovalve
 assign wSBWriteAddress
344
 = (rTagMemOwner == `TAGMEM_OWNER_ISSUE) ? ((rBypassFifo)?iResultBcast[`COMMIT_DST_RNG]:wDestinationIndex)
345
 : wResultFifoData[`COMMIT_DST_RNG];
346
`endif
347
 
348
assign wSBWriteData
349
= (rTagMemOwner == `TAGMEM_OWNER_ISSUE) ? ((rBypassFifo)?1'b0:wReservationStation) : 4'b0;
350
 
351
wire wTagMemoryWE;
352
assign wTagMemoryWE = rTagMemoryWE;//(rTagMemoryWE && (iInstruction0[`INST_CODE_RNG] != `OPERATION_OUT));       //Dont store dependencies for IO operations
353
 
354
RAM_DUAL_READ_PORT # ( SB_ENTRY_WIDTH, `DATA_ADDRESS_WIDTH ) SB
355
(
356
 .Clock(             Clock                          ),
357
 .iWriteEnable(      wTagMemoryWE                   ),
358
 .iReadAddress0(     oSourceAddress0                ),
359
 .iReadAddress1(     oSourceAddress1                ),
360
 .iWriteAddress(     wSBWriteAddress                ),
361
 .iDataIn(           wSBWriteData                   ),
362
 .oDataOut0(         wSBDataPort0                   ),
363
 .oDataOut1(         wSBDataPort1                   )
364
);
365
 
366
 
367
wire [`INSTRUCTION_ADDR_WIDTH-1:0]  wPCInitialValue;
368
wire [`INSTRUCTION_ADDR_WIDTH-1:0] wPCInitialTmp;
369
assign wPCInitialTmp = (iInstruction0[`INST_IMM])? wSourceData0[`SRC_RET_ADDR_RNG] : {2'b0,iInstruction0[`INST_DST_RNG]};
370
 
371
 
372
 
373
assign wPCInitialValue =  (rSetPCBranchTaken & ~Reset) ? wPCInitialTmp :  iCodeOffset;
374
 
375
 
376
 
377
//The program counter
378
UPCOUNTER_POSEDGE # (`INSTRUCTION_ADDR_WIDTH ) PC
379
(
380
        .Clock(    Clock                       ),
381
        .Reset(    Reset | rSetPCBranchTaken   ),
382
        .Enable(   rIncrementPC  & ~wStall     ),
383
        .Initial(  wPCInitialValue             ),
384
        .Q(        oIP0                        )
385
);
386
 
387
assign oIP1 = iInstruction0[`INST_DST_RNG];
388
 
389
 
390
`ifdef ADDRESSING_MODES_DISABLED
391
assign oSourceAddress1     = iInstruction0[`INST_SCR1_ADDR_RNG];
392
 
393
 
394
`else
395
 
396
assign oSourceAddress1 = (iInstruction0[`INST_IMM]) ? wSourceAddress1_Imm :
397
((iInstruction0[`INST_SRC1_DISPLACED]) ? wSource1Addr_Displaced: iInstruction0[`INST_SCR1_ADDR_RNG]);
398
 
399
assign wSource1Addr_Displaced = iInstruction0[`INST_SCR1_ADDR_RNG] + iFrameOffset;
400
assign wSource1Addr_Displaced_plus_Index = wSource1Addr_Displaced + iIndexRegister;
401
 
402
 MUXFULLPARALELL_3SEL_GENERIC # ( `DATA_ADDRESS_WIDTH ) SRC1ADDRMUX
403
 (
404
 .Sel(iInstruction0[`INST_ADDRMODE_RNG]),
405
 .I1(`DATA_ADDRESS_WIDTH'b0),
406
 .I2(`DATA_ADDRESS_WIDTH'b0),
407
 .I3(iInstruction0[`INST_SCR1_ADDR_RNG]),
408
 .I4(iInstruction0[`INST_SCR1_ADDR_RNG]),
409
 .I5(`DATA_ADDRESS_WIDTH'b0),
410
 .I6(`DATA_ADDRESS_WIDTH'b0),
411
 .I7(wSource1Addr_Displaced_plus_Index),
412
 .I8(wSource1Addr_Displaced_plus_Index),
413
 .O1(wSourceAddress1_Imm)
414
 );
415
`endif
416
 
417
 
418
`ifdef ADDRESSING_MODES_DISABLED
419
assign oSourceAddress0     = (iInstruction0[`INST_IMM] ) ? iInstruction0[`INST_DST_RNG] : iInstruction0[`INST_SRC0_ADDR_RNG];
420
`else
421
 
422
assign oSourceAddress0 = (iInstruction0[`INST_IMM]) ? wSourceAddress0_Imm :
423
((iInstruction0[`INST_SRC0_DISPLACED]) ? wSource0Addr_Displaced: iInstruction0[`INST_SRC0_ADDR_RNG]);
424
 
425
assign wSource0Addr_Displaced = iInstruction0[`INST_SRC0_ADDR_RNG] + iFrameOffset;
426
assign wSource0Addr_Displaced_plus_Index = wSource0Addr_Displaced + iIndexRegister;
427
 
428
MUXFULLPARALELL_2SEL_GENERIC # ( `DATA_ADDRESS_WIDTH ) SRC0ADDRMUX
429
 (
430
 .Sel({iInstruction0[`INST_SRC1_DISPLACED],iInstruction0[`INST_SRC0_DISPLACED]}),
431
 .I1(iInstruction0[`INST_DST_RNG]),
432
 .I2(iInstruction0[`INST_DST_RNG]),
433
 .I3(wSource0Addr_Displaced_plus_Index),
434
 .I4(wSource0Addr_Displaced),
435
 .O1(wSourceAddress0_Imm)
436
 );
437
 
438
`endif
439
 
440
 
441
assign wCommitBusDataAvailabe = ((iResultBcast[`COMMIT_RSID_RNG] != `OPERATION_NOP) && (~iIgnoreResultBcast));
442
 
443
 
444
sync_fifo  # (`COMMIT_PACKET_SIZE,2 ) RESULT_IN_FIFO
445
(
446
 .clk(    Clock              ),
447
 .reset(  Reset              ),
448
 .din(    iResultBcast       ),
449
 .wr_en(  wCommitBusDataAvailabe  ),
450
 .rd_en(  rPopFifo           ),
451
 .dout(   wResultFifoData    ),
452
 .empty(  wCommitBusInputFifo_Empty   )
453
 
454
);
455
 
456
 
457
 
458
 
459
 
460
//Source 1 for IMM values is really DST
461
 
462
//Reservation station for SRC0 when handling IMM values is zero
463
 
464
wire wSB0FromInCommit,wSB0ForwardDetected;
465
wire wSB1FromInCommit,wSB1ForwardDetected;
466
 
467
assign wSB0FromInCommit = 1'b0;//(rIssueNow && (iResultBcast[`COMMIT_DST_RNG] == oSourceAddress0)) ? 1'b1 : 1'b0;
468
assign wSB1FromInCommit = 1'b0;//(rIssueNow && (iResultBcast[`COMMIT_DST_RNG] == oSourceAddress1)) ? 1'b1 : 1'b0;
469
 
470
`ifdef ADDRESSING_MODES_DISABLED
471
wire [`DATA_ADDRESS_WIDTH-1:0] wTmpAddr0;
472
assign wTmpAddr0 = (iInstruction0[`INST_IMM])  ? iInstruction0[`INST_DST_RNG] : iInstruction0[`INST_SRC0_ADDR_RNG];
473
 
474
assign wSB0ForwardDetected = (rUseForwardedData && (wCommitData_Latched[`COMMIT_DST_RNG] == wTmpAddr0) ) ? 1'b1 : 1'b0;
475
assign wSB1ForwardDetected = (rUseForwardedData && (wCommitData_Latched[`COMMIT_DST_RNG] == iInstruction0[`INST_SCR1_ADDR_RNG]) ) ? 1'b1 : 1'b0;
476
`else
477
wire [`DATA_ADDRESS_WIDTH-1:0] wTmpAddr0,wTmpAddr1;
478
assign wTmpAddr0 = oSourceAddress0;
479
assign wTmpAddr1 = oSourceAddress1;
480
 
481
assign wSB0ForwardDetected = (rUseForwardedData && (wCommitData_Latched[`COMMIT_DST_RNG] == wTmpAddr0) /*&& ( wSource0_Station == iResultBcast[`COMMIT_RSID_RNG])*/ ) ? 1'b1 : 1'b0;
482
assign wSB1ForwardDetected = (rUseForwardedData && (wCommitData_Latched[`COMMIT_DST_RNG] == wTmpAddr1) /*&& ( wSource1_Station == iResultBcast[`COMMIT_RSID_RNG])*/ ) ? 1'b1 : 1'b0;
483
`endif
484
 
485
//FIX!!! FIX!!! Use the table to know when dependencies for SRC0 and SRC1 are don't care
486
//Fix this should not be (iInstruction0[`INST_IMM] & iInstruction0[`INST_DEST_ZERO]) but isntead should use the table
487
assign wSource0_Station = (wSB0FromInCommit | wSB0ForwardDetected | (iInstruction0[`INST_IMM] & iInstruction0[`INST_DEST_ZERO])) ? 4'b0    : wSBDataPort0;
488
assign wSource1_Station = (iInstruction0[`INST_IMM] | wSB1FromInCommit | wSB1ForwardDetected) ? 4'b0: wSBDataPort1;
489
 
490
 
491
//Handle literal values for IMM. IMM is stored in SRC1.X
492
 
493
 
494
wire [`DATA_ROW_WIDTH-1:0]  wImmValue,wSource1_Temp,wSource0_Temp,wSourceData1_Imm,wSourceData0_Imm;
495
assign wImmValue[`X_RNG] = (iInstruction0[`INST_WE_X]) ? iInstruction0[`INST_IMM_RNG] : `WIDTH'b0;
496
assign wImmValue[`Y_RNG] = (iInstruction0[`INST_WE_Y]) ? iInstruction0[`INST_IMM_RNG] : `WIDTH'b0;
497
assign wImmValue[`Z_RNG] = (iInstruction0[`INST_WE_Z]) ? iInstruction0[`INST_IMM_RNG] : `WIDTH'b0;
498
 
499
 
500
 
501
assign wSource1_Temp[`X_RNG] = (wSB1FromInCommit & iResultBcast[`COMMIT_WE_X]) ? iResultBcast[`COMMIT_X_RNG] :
502
( (wSB1ForwardDetected & wCommitData_Latched[`COMMIT_WE_X])? wCommitData_Latched[`X_RNG] : iSourceData1[`X_RNG]);
503
 
504
assign wSource1_Temp[`Y_RNG] = (wSB1FromInCommit & iResultBcast[`COMMIT_WE_Y]) ? iResultBcast[`COMMIT_Y_RNG] :
505
( (wSB1ForwardDetected & wCommitData_Latched[`COMMIT_WE_Y]) ? wCommitData_Latched[`Y_RNG] : iSourceData1[`Y_RNG]);
506
 
507
 
508
assign wSource1_Temp[`Z_RNG] = (wSB1FromInCommit & iResultBcast[`COMMIT_WE_Z]) ? iResultBcast[`COMMIT_Z_RNG] :
509
( (wSB1ForwardDetected & wCommitData_Latched[`COMMIT_WE_Z]) ?  wCommitData_Latched[`Z_RNG] : iSourceData1[`Z_RNG]);
510
 
511
assign wSource0_Temp[`X_RNG] =  (wSB0FromInCommit & iResultBcast[`COMMIT_WE_X]) ? iResultBcast[`COMMIT_X_RNG]:
512
( (wSB0ForwardDetected & & wCommitData_Latched[`COMMIT_WE_X] )? wCommitData_Latched[`X_RNG]:iSourceData0[`X_RNG]);
513
 
514
 
515
assign wSource0_Temp[`Y_RNG] =  (wSB0FromInCommit & iResultBcast[`COMMIT_WE_Y]) ? iResultBcast[`COMMIT_Y_RNG]:
516
( (wSB0ForwardDetected & & wCommitData_Latched[`COMMIT_WE_Y])? wCommitData_Latched[`Y_RNG] : iSourceData0[`Y_RNG]);
517
 
518
assign wSource0_Temp[`Z_RNG] =  (wSB0FromInCommit & iResultBcast[`COMMIT_WE_Z]) ? iResultBcast[`COMMIT_Z_RNG]:
519
( (wSB0ForwardDetected & & wCommitData_Latched[`COMMIT_WE_Z])? wCommitData_Latched[`Z_RNG] : iSourceData0[`Z_RNG]);
520
 
521
 
522
 
523
//If the data we are looking for just arrived at iResultBcast the use that
524
//other wise used the data from the Register file or the Immediate values
525
//assign wSourceData1 = (iInstruction0[`INST_IMM]) ? wImmValue : wSource1_Temp;
526
//assign wSourceData0 = (iInstruction0[`INST_IMM] && iInstruction0[`INST_DEST_ZERO]) ? `DATA_ROW_WIDTH'd0 : wSource0_Temp;
527
 
528
 
529
assign wSourceData1 = (iInstruction0[`INST_IMM]) ? wSourceData1_Imm : wSource1_Temp;
530
assign wSourceData0 = (iInstruction0[`INST_IMM]) ? wSourceData0_Imm : wSource0_Temp;
531
//assign wSourceData0 = (iInstruction0[`INST_IMM] && iInstruction0[`INST_DEST_ZERO]) ? `DATA_ROW_WIDTH'd0 : wSource0_Temp;
532
 
533
MUXFULLPARALELL_3SEL_GENERIC # ( `DATA_ROW_WIDTH ) SRC1MUX
534
 (
535
 .Sel({iInstruction0[`INST_DEST_ZERO],iInstruction0[`INST_SRC1_DISPLACED],iInstruction0[`INST_SRC0_DISPLACED]}),
536
 .I1(wImmValue),
537
 .I2(wImmValue),
538
 .I3(wSource1_Temp),
539
 .I4( `DATA_ROW_WIDTH'b0),
540
 .I5( wImmValue ),
541
 .I6( wImmValue ),
542
 .I7( wSource1_Temp ),
543
 .I8( wSource1_Temp ),
544
 .O1(wSourceData1_Imm)
545
 );
546
 
547
 
548
MUXFULLPARALELL_3SEL_GENERIC # ( `DATA_ROW_WIDTH ) SRC0MUX
549
 (
550
 .Sel({iInstruction0[`INST_DEST_ZERO],iInstruction0[`INST_SRC1_DISPLACED],iInstruction0[`INST_SRC0_DISPLACED]}),
551
 .I1(   wSource0_Temp      ),
552
 .I2(   wSource0_Temp      ),
553
 .I3(   wSource0_Temp      ),
554
 .I4(   wSource0_Temp      ),
555
 .I5(  `DATA_ROW_WIDTH'b0  ),
556
 .I6(  `DATA_ROW_WIDTH'b0  ),
557
 .I7(  `DATA_ROW_WIDTH'b0  ),
558
 .I8(   wSource0_Temp      ),
559
 .O1(   wSourceData0_Imm      )
560
 );
561
 
562
 
563
assign wReservationStationBusy = (~iEnable) |
564
(
565
((iInstruction0[`INST_CODE_RNG] == `OPERATION_ADD ) && (iRStationBusy[ 0  ] && iRStationBusy[ 1  ])) ||
566
((iInstruction0[`INST_CODE_RNG] == `OPERATION_DIV ) &&  iRStationBusy[ 2  ]) ||
567
((iInstruction0[`INST_CODE_RNG] == `OPERATION_MUL ) &&  iRStationBusy[ 3  ]) ||
568 230 diegovalve
((iInstruction0[`INST_CODE_RNG] == `OPERATION_IO ) &&  iRStationBusy[ 6  ])
569 213 diegovalve
);
570
 
571
assign wBranchWithDependency = (iInstruction0[`INST_BRANCH_BIT] && (wSource0_Station != 0 || wSource1_Station != 0));
572
 
573
 
574
assign wOp = iInstruction0[`INST_CODE_RNG];
575 230 diegovalve
//The next equations calculate the reservations stations ID based on the current operation and the availability
576
//of the RS's (that is if a given statation is busy choose another suitable 1). To understand this equations
577
//please refer to the table TBD in the architecture specification document
578 213 diegovalve
 
579
assign wReservationStation[0] =
580
(wOp[0]  & ~wOp[1] & ~wOp[2] & ~wOp[3] & ~iRStationBusy[ 0  ]) |
581
(~wOp[0] &  wOp[1] & ~wOp[2] & ~wOp[3] & ~iRStationBusy[ 2  ]) |
582
(~wOp[0] & ~wOp[1] & wOp[2] & ~wOp[3]  & ~iRStationBusy[ 4  ]) |
583
(~wOp[0] &  wOp[1] & wOp[2] & ~wOp[3]  & ~iRStationBusy[ 6  ]);
584
 
585
assign wReservationStation[1] =
586
(~wOp[0] &  wOp[1] & wOp[2] & ~wOp[3]  & ~iRStationBusy[ 6  ]) |
587
(wOp[0] & ~wOp[1] & wOp[2] & ~wOp[3]  & ~iRStationBusy[5]   ) |
588
(wOp[0] & ~wOp[1] & ~wOp[2] & ~wOp[3] & iRStationBusy[ 0  ] & ~iRStationBusy[1]) |
589
(~wOp[0] & wOp[1] & ~wOp[2] & ~wOp[3] & ~iRStationBusy[ 2  ]);
590
 
591
 
592
assign wReservationStation[2] =
593
(~wOp[0] &  wOp[1] & wOp[2] & ~wOp[3]  & ~iRStationBusy[ 6  ]) |
594
(wOp[0] & ~wOp[1] & wOp[2] & ~wOp[3]  & ~iRStationBusy[5]) |
595
(wOp[0] & wOp[1] & ~wOp[2] & ~wOp[3]  & ~iRStationBusy[3]) |
596
(~wOp[0] & ~wOp[1] & wOp[2] & ~wOp[3] & ~iRStationBusy[ 4  ]);
597
 
598
assign wReservationStation[3] = 1'b0;
599
 
600
//Sign control logic.
601
//Only works for non literal opeations (INST_IMM == 0)
602
wire [`ISSUE_SRCTAG_SIZE-1:0]  wIssueTag0,wIssueTag1;
603
 
604
 assign wIssueTag0 = (iInstruction0[`INST_IMM]) ? `ISSUE_SRCTAG_SIZE'b0 : {iInstruction0[`INST_SRC0_SIGN_RNG],iInstruction0[`INST_SRC0_SWZL_RNG] };
605
 assign wIssueTag1 = (iInstruction0[`INST_IMM]) ? `ISSUE_SRCTAG_SIZE'b0 : {iInstruction0[`INST_SRC1_SIGN_RNG],iInstruction0[`INST_SCR1_SWZL_RNG] };
606
 
607
wire [`DATA_ADDRESS_WIDTH -1:0] wDestinationIndex;
608
 
609
 
610
`ifdef ADDRESSING_MODES_DISABLED
611
assign wDestinationIndex = iInstruction0[`INST_DST_RNG];
612
`else
613
 
614
wire [`DATA_ADDRESS_WIDTH -1:0] wDestIndexDisplaced,wDestinationIndex_NoIMM,wDestinationIndex_IMM;
615
 
616
assign wDestIndexDisplaced     = (iInstruction0[`INST_DST_RNG] + iFrameOffset);
617
assign wDestinationIndex_NoIMM = (iInstruction0[`INST_DEST_ZERO])               ? wDestIndexDisplaced : iInstruction0[`INST_DST_RNG];
618
 
619 230 diegovalve
wire [`WIDTH-1:0 ] wSource1_X;
620
assign wSource1_X = wSource1_Temp[`X_RNG];
621 213 diegovalve
 
622
MUXFULLPARALELL_3SEL_GENERIC # ( `DATA_ADDRESS_WIDTH ) DSTMUX
623
 (
624
 .Sel({iInstruction0[`INST_DEST_ZERO],iInstruction0[`INST_SRC1_DISPLACED],iInstruction0[`INST_SRC0_DISPLACED]}),
625
 .I1(iInstruction0[`INST_DST_RNG]),
626
 .I2(wDestIndexDisplaced),
627
 .I3(wDestIndexDisplaced),
628 230 diegovalve
 .I4(wDestIndexDisplaced + wSource1_X[`DATA_ADDRESS_WIDTH-1:0]),
629 213 diegovalve
 .I5(iInstruction0[`INST_DST_RNG]),
630
 .I6(wDestIndexDisplaced),
631
 .I7(iInstruction0[`INST_DST_RNG]),
632
 .I8(wDestIndexDisplaced),
633
 .O1(wDestinationIndex_IMM)
634
 );
635
 
636
 
637
assign wDestinationIndex = (iInstruction0[`INST_IMM]) ? wDestinationIndex_IMM : wDestinationIndex_NoIMM;
638
`endif
639
 
640
assign oIssueBcast = (Reset | ~rIssueNow | wStall ) ? `ISSUE_PACKET_SIZE'b0 :
641
{
642
wReservationStation,
643
wDestinationIndex,
644
iInstruction0[`INST_WE_RNG],
645
iInstruction0[`INST_SCOP_RNG],
646
wSource1_Station,
647
wIssueTag1,
648
wSourceData1,
649
wSource0_Station,
650
wIssueTag0,
651
wSourceData0
652
 
653
};
654
 
655
endmodule

powered by: WebSVN 2.1.0

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