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 172

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

powered by: WebSVN 2.1.0

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