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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [icarus_version/] [rtl/] [Module_InstructionDecode.v] - Blame information for rev 182

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

Line No. Rev Author Line
1 158 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
module InstructionDecode
24
(
25 175 diegovalve
input wire                                Clock,
26
input wire                                Reset,
27
input wire                                iInstructionAvailable,
28
input wire[`INSTRUCTION_WIDTH-1:0]        iEncodedInstruction,
29
input wire[`DATA_ROW_WIDTH-1:0]           iRamValue0,
30
input wire[`DATA_ROW_WIDTH-1:0]           iRamValue1,
31
output  wire[`DATA_ADDRESS_WIDTH-1:0]     oRamAddress0,oRamAddress1,
32
output  wire[`INSTRUCTION_OP_LENGTH-1:0]  oOperation,
33
output  wire [`DATA_ROW_WIDTH-1:0]        oSource0,oSource1,
34
output  wire [`DATA_ADDRESS_WIDTH-1:0]    oDestination,
35 158 diegovalve
input wire [`DATA_ROW_WIDTH-1:0]          iDataForward,
36
input wire [`DATA_ADDRESS_WIDTH-1:0]      iLastDestination,
37
 
38
`ifdef DEBUG
39 175 diegovalve
 input wire [`ROM_ADDRESS_WIDTH-1:0]      iDebug_CurrentIP,
40
 output wire [`ROM_ADDRESS_WIDTH-1:0]     oDebug_CurrentIP,
41 158 diegovalve
`endif
42
 
43 175 diegovalve
 
44 158 diegovalve
output wire                               oDataReadyForExe
45
 
46
);
47
wire wInmediateOperand;
48 175 diegovalve
wire [`DATA_ROW_WIDTH-1:0] wSource0,wSource1;
49 158 diegovalve
wire wTriggerSource0DataForward,wTriggerSource1DataForward;
50
wire wSource0AddrssEqualsLastDestination,wSource1AddrssEqualsLastDestination;
51
 
52
`ifdef DEBUG
53
assign oDebug_CurrentIP = iDebug_CurrentIP;
54
`endif
55
//See if operation takes scalar argument
56
assign wInmediateOperand = iEncodedInstruction[`INSTRUCTION_IMM_BITPOS];
57
 
58
//Has the value of the first argument fetched from IMEM
59
assign wSource0 = iRamValue0;
60
//Has the value of the second argument fetched from IMEM, or the value of the
61
//destinatin register in case of scalar operation
62
assign wSource1 = ( wInmediateOperand ) ? {oRamAddress1,iEncodedInstruction[15:0] ,32'b0,32'b0} : iRamValue1; //{oRamAddress1,oRamAddress0,32'b0,32'b0} : iRamValue1;
63
 
64
//Data forwarding logic
65
assign wSource0AddrssEqualsLastDestination = (oRamAddress0 == iLastDestination) ? 1'b1: 1'b0;
66
assign wSource1AddrssEqualsLastDestination = (oRamAddress1 == iLastDestination) ? 1'b1: 1'b0;
67
assign wTriggerSource0DataForward = wSource0AddrssEqualsLastDestination;
68
assign wTriggerSource1DataForward = wSource1AddrssEqualsLastDestination && !wInmediateOperand;
69
 
70
//The data address to fetch from IMEM
71
assign oRamAddress1 = iEncodedInstruction[31:16];
72
 
73
//If operation takes a scalar value, then ask IMEM
74
//for the previous value of the destination ([47:32])
75
//and have this value ready at oRamAddress0
76
MUXFULLPARALELL_16bits_2SEL RAMAddr0MUX
77
 (
78
  .Sel( wInmediateOperand ),
79
  .I1( iEncodedInstruction[15:0] ),
80
  .I2( iEncodedInstruction[47:32] ),
81
  .O1( oRamAddress0 )
82
 );
83
 
84
 
85
//One clock cycle after the new instruction becomes
86
//available to IDU, it should be decoded and ready 
87
//for execution
88
FFD_POSEDGE_SYNCRONOUS_RESET # ( 1 ) FFD1
89
(
90 175 diegovalve
 .Clock( Clock ),
91
 .Reset( Reset ),
92
 .Enable(1'b1),
93
 .D( iInstructionAvailable ),
94
 .Q( oDataReadyForExe )
95 158 diegovalve
);
96
 
97
 
98
//Latch the Operation
99
FFD_POSEDGE_SYNCRONOUS_RESET # ( `INSTRUCTION_OP_LENGTH ) FFD3
100
(
101 175 diegovalve
 .Clock(Clock),
102
 .Reset(Reset),
103
 .Enable(iInstructionAvailable),
104
 .D(iEncodedInstruction[`INSTRUCTION_WIDTH-1:`INSTRUCTION_WIDTH-`INSTRUCTION_OP_LENGTH]),
105
 .Q( oOperation )
106 158 diegovalve
);
107
//Latch the Destination
108
FFD_POSEDGE_SYNCRONOUS_RESET # ( `DATA_ADDRESS_WIDTH ) FFD2
109
(
110 175 diegovalve
 .Clock(Clock),
111
 .Reset(Reset),
112
 .Enable(iInstructionAvailable),
113
 .D(iEncodedInstruction[47:32]),
114
 .Q(oDestination )
115 158 diegovalve
);
116
 
117
 
118
//Once we made a decicions if the Sources must be forwarded or not, a series of muxes
119
//are used to routed the correct data into the decoded Source outputs
120
 
121
MUXFULLPARALELL_96bits_2SEL Source0_Mux
122
(
123 175 diegovalve
 .Sel( wTriggerSource0DataForward ),
124
 .I1( wSource0  ),
125
 .I2( iDataForward ),
126
 .O1( oSource0 )
127 158 diegovalve
);
128
 
129
MUXFULLPARALELL_96bits_2SEL Source1_Mux
130
(
131 175 diegovalve
 .Sel( wTriggerSource1DataForward ),
132
 .I1( wSource1  ),
133
 .I2( iDataForward ),
134
 .O1( oSource1 )
135 158 diegovalve
);
136
 
137
endmodule
138
 

powered by: WebSVN 2.1.0

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