1 |
22 |
diegovalve |
`timescale 1ns / 1ps
|
2 |
|
|
`include "aDefinitions.v"
|
3 |
|
|
/**********************************************************************************
|
4 |
|
|
Theia, Ray Cast Programable graphic Processing Unit.
|
5 |
|
|
Copyright (C) 2010 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 |
|
|
//---------------------------------------------------------------------
|
24 |
|
|
module ExecutionUnit
|
25 |
|
|
(
|
26 |
|
|
|
27 |
|
|
input wire Clock,
|
28 |
|
|
input wire Reset,
|
29 |
|
|
input wire [`ROM_ADDRESS_WIDTH-1:0] iInitialCodeAddress,
|
30 |
|
|
input wire [`INSTRUCTION_WIDTH-1:0] iEncodedInstruction,
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
input wire [`DATA_ROW_WIDTH-1:0] iDataRead0,
|
34 |
|
|
input wire [`DATA_ROW_WIDTH-1:0] iDataRead1,
|
35 |
|
|
input wire iTrigger,
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
output wire [`ROM_ADDRESS_WIDTH-1:0] oInstructionPointer,
|
39 |
|
|
output wire [`DATA_ADDRESS_WIDTH-1:0] oDataReadAddress0,
|
40 |
|
|
output wire [`DATA_ADDRESS_WIDTH-1:0] oDataReadAddress1,
|
41 |
|
|
output wire oDataWriteEnable,
|
42 |
|
|
output wire [`DATA_ADDRESS_WIDTH-1:0] oDataWriteAddress,
|
43 |
|
|
output wire [`DATA_ROW_WIDTH-1:0] oDataBus,
|
44 |
|
|
output wire oReturnCode,
|
45 |
|
|
output wire oDone
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
);
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
`ifdef DEBUG
|
54 |
|
|
wire [`ROM_ADDRESS_WIDTH-1:0] wDEBUG_IDU2_EXE_InstructionPointer;
|
55 |
|
|
`endif
|
56 |
|
|
|
57 |
|
|
wire wEXE2__uCodeDone;
|
58 |
|
|
wire wEXE2_IFU__EXEBusy;
|
59 |
|
|
wire [`DATA_ADDRESS_WIDTH-1:0] wEXE2_IDU_DataFordward_LastDestination;
|
60 |
|
|
wire wALU2_EXE__BranchTaken;
|
61 |
|
|
wire wALU2_IFU_BranchNotTaken;
|
62 |
|
|
wire [`INSTRUCTION_WIDTH-1:0] CurrentInstruction;
|
63 |
|
|
wire wIDU2_IFU__IDUBusy;
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
wire [`INSTRUCTION_OP_LENGTH-1:0] wOperation;
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
wire [`DATA_ROW_WIDTH-1:0] wSource0,wSource1;
|
70 |
|
|
wire [`DATA_ADDRESS_WIDTH-1:0] wDestination;
|
71 |
|
|
wire wInstructionAvailable;
|
72 |
|
|
|
73 |
|
|
//ALU wires
|
74 |
|
|
wire [`INSTRUCTION_OP_LENGTH-1:0] ALU2Operation;
|
75 |
|
|
wire [`WIDTH-1:0] ALU2ChannelA;
|
76 |
|
|
wire [`WIDTH-1:0] ALU2ChannelB;
|
77 |
|
|
wire [`WIDTH-1:0] ALU2ChannelC;
|
78 |
|
|
wire [`WIDTH-1:0] ALU2ChannelD;
|
79 |
|
|
wire [`WIDTH-1:0] ALU2ChannelE;
|
80 |
|
|
wire [`WIDTH-1:0] ALU2ChannelF;
|
81 |
|
|
wire [`WIDTH-1:0] ALU2ResultA;
|
82 |
|
|
wire [`WIDTH-1:0] ALU2ResultB;
|
83 |
|
|
wire [`WIDTH-1:0] ALU2ResultC;
|
84 |
|
|
wire wEXE2_ALU__TriggerALU;
|
85 |
|
|
wire ALU2OutputReady;
|
86 |
|
|
wire JumpFlag;
|
87 |
|
|
wire [`ROM_ADDRESS_WIDTH-1:0] JumpIp;
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
wire wIDU2_IFU__InputsLatched;
|
91 |
|
|
|
92 |
|
|
InstructionFetchUnit IFU
|
93 |
|
|
(
|
94 |
|
|
.Clock( Clock ),
|
95 |
|
|
.Reset( Reset ),
|
96 |
|
|
.iTrigger( iTrigger ),
|
97 |
|
|
.iInitialCodeAddress( iInitialCodeAddress ),
|
98 |
|
|
.oCurrentInstruction( CurrentInstruction ),
|
99 |
|
|
.oInstructionAvalable( wInstructionAvailable ),
|
100 |
|
|
.oInstructionPointer( oInstructionPointer ),
|
101 |
|
|
.iEncodedInstruction( iEncodedInstruction ),
|
102 |
|
|
.oExecutionDone( oDone ),
|
103 |
|
|
.iBranchTaken( JumpFlag ),
|
104 |
|
|
.iBranchNotTaken( wALU2_IFU_BranchNotTaken ),
|
105 |
|
|
.iJumpIp( JumpIp ),
|
106 |
|
|
.iIDUBusy( wIDU2_IFU__IDUBusy ),
|
107 |
|
|
.iExeBusy( wEXE2_IFU__EXEBusy ),
|
108 |
|
|
.iDecodeUnitLatchedValues( wIDU2_IFU__InputsLatched ),
|
109 |
|
|
.oMicroCodeReturnValue( oReturnCode )
|
110 |
|
|
|
111 |
|
|
);
|
112 |
|
|
////---------------------------------------------------------
|
113 |
|
|
wire wIDU2_EXE_DataReady;
|
114 |
|
|
wire wEXE2_IDU_ExeLatchedValues;
|
115 |
|
|
|
116 |
|
|
InstructionDecode IDU
|
117 |
|
|
(
|
118 |
|
|
.Clock( Clock ),
|
119 |
|
|
.Reset( Reset ),
|
120 |
|
|
.iTrigger( iTrigger ),
|
121 |
|
|
.iEncodedInstruction( CurrentInstruction ),
|
122 |
|
|
.iInstructionAvailable( wInstructionAvailable ),
|
123 |
|
|
.iExecutioUnitLatchedValues( wEXE2_IDU_ExeLatchedValues ),
|
124 |
|
|
.oRamAddress0( oDataReadAddress0 ),
|
125 |
|
|
.oRamAddress1( oDataReadAddress1 ),
|
126 |
|
|
.iRamValue0( iDataRead0 ),
|
127 |
|
|
.iRamValue1( iDataRead1 ),
|
128 |
|
|
.iLastDestination( wEXE2_IDU_DataFordward_LastDestination ),
|
129 |
|
|
.iDataForward( {ALU2ResultA,ALU2ResultB,ALU2ResultC} ),
|
130 |
|
|
|
131 |
|
|
//Outputs going to the ALU-FSM
|
132 |
|
|
.oOperation( wOperation ),
|
133 |
|
|
.oDestination( wDestination ),
|
134 |
|
|
.oSource0( wSource0 ),
|
135 |
|
|
.oSource1( wSource1 ),
|
136 |
|
|
.oInputsLatched( wIDU2_IFU__InputsLatched ),
|
137 |
|
|
.oDataReadyForExe( wIDU2_EXE_DataReady ),
|
138 |
|
|
|
139 |
|
|
`ifdef DEBUG
|
140 |
|
|
.iDebug_CurrentIP( oInstructionPointer ),
|
141 |
|
|
.oDebug_CurrentIP( wDEBUG_IDU2_EXE_InstructionPointer ),
|
142 |
|
|
`endif
|
143 |
|
|
.oBusy( wIDU2_IFU__IDUBusy )
|
144 |
|
|
//.oDecodeDone( wEXE2__uCodeDone )
|
145 |
|
|
);
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
ExecutionFSM EXE
|
150 |
|
|
(
|
151 |
|
|
.Clock( Clock ),
|
152 |
|
|
.Reset( Reset ),
|
153 |
|
|
.iDecodeDone( wIDU2_EXE_DataReady ),
|
154 |
|
|
.iOperation( wOperation ),
|
155 |
|
|
.iDestination( wDestination ),
|
156 |
|
|
.iSource0( wSource0 ),
|
157 |
|
|
.iSource1( wSource1 ) ,
|
158 |
|
|
|
159 |
|
|
`ifdef DEBUG
|
160 |
|
|
.iDebug_CurrentIP( wDEBUG_IDU2_EXE_InstructionPointer ),
|
161 |
|
|
`endif
|
162 |
|
|
|
163 |
|
|
//.iJumpResultFromALU( wALU2_EXE__BranchTaken ),
|
164 |
|
|
.iBranchTaken( wALU2_EXE__BranchTaken ),
|
165 |
|
|
.iBranchNotTaken( wALU2_IFU_BranchNotTaken ),
|
166 |
|
|
.oJumpFlag( JumpFlag ),
|
167 |
|
|
.oJumpIp( JumpIp ),
|
168 |
|
|
.oRAMWriteEnable( oDataWriteEnable ),
|
169 |
|
|
.oRAMWriteAddress( oDataWriteAddress ),
|
170 |
|
|
.RAMBus( oDataBus ),
|
171 |
|
|
.oBusy( wEXE2_IFU__EXEBusy ),
|
172 |
|
|
|
173 |
|
|
.oExeLatchedValues( wEXE2_IDU_ExeLatchedValues ),
|
174 |
|
|
.oLastDestination( wEXE2_IDU_DataFordward_LastDestination ),
|
175 |
|
|
|
176 |
|
|
//ALU ports and control signals
|
177 |
|
|
.oTriggerALU( wEXE2_ALU__TriggerALU ),
|
178 |
|
|
.oALUOperation( ALU2Operation ),
|
179 |
|
|
.oALUChannelX1( ALU2ChannelA ),
|
180 |
|
|
.oALUChannelX2( ALU2ChannelB ),
|
181 |
|
|
.oALUChannelY1( ALU2ChannelC ),
|
182 |
|
|
.oALUChannelY2( ALU2ChannelD ),
|
183 |
|
|
.oALUChannelZ1( ALU2ChannelE ),
|
184 |
|
|
.oALUChannelZ2( ALU2ChannelF ),
|
185 |
|
|
.iALUResultX( ALU2ResultA ),
|
186 |
|
|
.iALUResultY( ALU2ResultB ),
|
187 |
|
|
.iALUResultZ( ALU2ResultC ),
|
188 |
|
|
.iALUOutputReady( ALU2OutputReady )
|
189 |
|
|
|
190 |
|
|
);
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
//--------------------------------------------------------
|
194 |
|
|
|
195 |
|
|
VectorALU ALU
|
196 |
|
|
(
|
197 |
|
|
.Clock(Clock),
|
198 |
|
|
.Reset(Reset),
|
199 |
|
|
.iOperation( ALU2Operation ),
|
200 |
|
|
.iChannel_Ax( ALU2ChannelA ),
|
201 |
|
|
.iChannel_Bx( ALU2ChannelB ),
|
202 |
|
|
.iChannel_Ay( ALU2ChannelC ),
|
203 |
|
|
.iChannel_By( ALU2ChannelD ),
|
204 |
|
|
.iChannel_Az( ALU2ChannelE ),
|
205 |
|
|
.iChannel_Bz( ALU2ChannelF ),
|
206 |
|
|
.oResultA( ALU2ResultA ),
|
207 |
|
|
.oResultB( ALU2ResultB ),
|
208 |
|
|
.oResultC( ALU2ResultC ),
|
209 |
|
|
.oBranchTaken( wALU2_EXE__BranchTaken ),
|
210 |
|
|
.oBranchNotTaken( wALU2_IFU_BranchNotTaken ),
|
211 |
|
|
.iInputReady( wEXE2_ALU__TriggerALU ),
|
212 |
|
|
.OutputReady( ALU2OutputReady )
|
213 |
|
|
|
214 |
|
|
);
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
endmodule
|
219 |
|
|
//---------------------------------------------------------------------
|