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

Subversion Repositories altor32

[/] [altor32/] [trunk/] [rtl/] [cpu/] [altor32_dfu.v] - Blame information for rev 40

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 ultra_embe
//-----------------------------------------------------------------
2
//                           AltOR32 
3
//                Alternative Lightweight OpenRisc 
4 36 ultra_embe
//                            V2.1
5 27 ultra_embe
//                     Ultra-Embedded.com
6 36 ultra_embe
//                   Copyright 2011 - 2014
7 27 ultra_embe
//
8
//               Email: admin@ultra-embedded.com
9
//
10
//                       License: LGPL
11
//-----------------------------------------------------------------
12
//
13 37 ultra_embe
// Copyright (C) 2011 - 2014 Ultra-Embedded.com
14 27 ultra_embe
//
15
// This source file may be used and distributed without         
16
// restriction provided that this copyright statement is not    
17
// removed from the file and that any derivative work contains  
18
// the original copyright notice and the associated disclaimer. 
19
//
20
// This source file is free software; you can redistribute it   
21
// and/or modify it under the terms of the GNU Lesser General   
22
// Public License as published by the Free Software Foundation; 
23
// either version 2.1 of the License, or (at your option) any   
24
// later version.
25
//
26
// This source is distributed in the hope that it will be       
27
// useful, but WITHOUT ANY WARRANTY; without even the implied   
28
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      
29
// PURPOSE.  See the GNU Lesser General Public License for more 
30
// details.
31
//
32
// You should have received a copy of the GNU Lesser General    
33
// Public License along with this source; if not, write to the 
34
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
35
// Boston, MA  02111-1307  USA
36
//-----------------------------------------------------------------
37
 
38
//-----------------------------------------------------------------
39
// Includes
40
//-----------------------------------------------------------------
41
`include "altor32_defs.v"
42
 
43
//-----------------------------------------------------------------
44
// Module: Data Forwarding Unit
45
//-----------------------------------------------------------------
46
module altor32_dfu
47
(
48
    // Input registers
49
    input [4:0]         ra_i /*verilator public*/,
50
    input [4:0]         rb_i /*verilator public*/,
51
 
52
    // Input register contents
53
    input [31:0]        ra_regval_i /*verilator public*/,
54
    input [31:0]        rb_regval_i /*verilator public*/,
55
 
56
    // Dest register (EXEC stage)
57
    input [4:0]         rd_ex_i/*verilator public*/,
58
 
59
    // Dest register (WB stage)
60
    input [4:0]         rd_wb_i/*verilator public*/,
61
 
62
    // Load pending / target
63
    input               load_pending_i /*verilator public*/,
64
    input [4:0]         rd_load_i /*verilator public*/,
65
 
66
    // Multiplier status
67 40 ultra_embe
    input               mult_ex_i /*verilator public*/,
68 27 ultra_embe
 
69
    // Result (EXEC)
70
    input [31:0]        result_ex_i /*verilator public*/,
71
 
72
    // Result (WB)
73
    input [31:0]        result_wb_i /*verilator public*/,
74
 
75
    // Resolved register values
76
    output reg [31:0]   result_ra_o /*verilator public*/,
77
    output reg [31:0]   result_rb_o /*verilator public*/,
78
 
79 36 ultra_embe
    // Result required resolving
80
    output reg          resolved_o /*verilator public*/,
81
 
82 27 ultra_embe
    // Stall due to failed resolve
83
    output reg          stall_o /*verilator public*/
84
);
85
 
86
//-------------------------------------------------------------------
87
// Data forwarding unit
88
//-------------------------------------------------------------------
89
always @ *
90
begin
91
   // Default to no forwarding
92
   result_ra_o  = ra_regval_i;
93
   result_rb_o  = rb_regval_i;
94
   stall_o      = 1'b0;
95 36 ultra_embe
   resolved_o   = 1'b0;
96 27 ultra_embe
 
97
   //---------------------------------------------------------------
98
   // RA - Hazard detection & forwarding
99
   //---------------------------------------------------------------
100
 
101
   // Register[ra] hazard detection & forwarding logic
102
   // (higher priority = latest results!)
103
   if (ra_i != 5'b00000)
104
   begin
105
       //---------------------------------------------------------------
106
       // RA from load (result not ready)
107
       //---------------------------------------------------------------
108
       if (ra_i == rd_load_i & load_pending_i)
109
       begin
110
            stall_o     = 1'b1;
111
`ifdef CONF_CORE_DEBUG
112
            $display(" rA[%d] not ready as load still pending", ra_i);
113
`endif
114
       end
115
       //---------------------------------------------------------------
116
       // RA from PC-4 (exec)
117
       //---------------------------------------------------------------
118
       else if (ra_i == rd_ex_i)
119
       begin
120
            // Multiplier has one cycle latency, stall if needed now
121 40 ultra_embe
            if (mult_ex_i)
122 27 ultra_embe
                stall_o     = 1'b1;
123
            else
124
            begin
125
                result_ra_o = result_ex_i;
126 36 ultra_embe
                resolved_o  = 1'b1;
127 27 ultra_embe
`ifdef CONF_CORE_DEBUG
128
                $display(" rA[%d] forwarded 0x%08x (PC-4)", ra_i, result_ra_o);
129
`endif
130
            end
131
       end
132
       //---------------------------------------------------------------
133
       // RA from PC-8 (writeback)
134
       //---------------------------------------------------------------
135
       else if (ra_i == rd_wb_i)
136
       begin
137 40 ultra_embe
            result_ra_o = result_wb_i;
138 27 ultra_embe
 
139 36 ultra_embe
            resolved_o  = 1'b1;
140 27 ultra_embe
`ifdef CONF_CORE_DEBUG
141
            $display(" rA[%d] forwarded 0x%08x (PC-8)", ra_i, result_ra_o);
142
`endif
143
       end
144
   end
145
 
146
   //---------------------------------------------------------------
147
   // RB - Hazard detection & forwarding
148
   //---------------------------------------------------------------       
149
 
150
   // Register[rb] hazard detection & forwarding logic
151
   // (higher priority = latest results!)
152
   if (rb_i != 5'b00000)
153
   begin
154
 
155
       //---------------------------------------------------------------
156
       // RB from load (result not ready)
157
       //---------------------------------------------------------------
158
       if (rb_i == rd_load_i & load_pending_i)
159
       begin
160
            stall_o     = 1'b1;
161
`ifdef CONF_CORE_DEBUG
162
            $display(" rB[%d] not ready as load still pending", rb_i);
163
`endif
164
       end
165
       //---------------------------------------------------------------
166
       // RB from PC-4 (exec)
167
       //---------------------------------------------------------------
168
       else if (rb_i == rd_ex_i)
169
       begin
170
            // Multiplier has one cycle latency, stall if needed now
171 40 ultra_embe
            if (mult_ex_i)
172 27 ultra_embe
                stall_o     = 1'b1;
173
            else
174
            begin
175
                result_rb_o = result_ex_i;
176 36 ultra_embe
                resolved_o  = 1'b1;
177 27 ultra_embe
 
178
`ifdef CONF_CORE_DEBUG
179
                $display(" rB[%d] forwarded 0x%08x (PC-4)", rb_i, result_rb_o);
180
`endif
181
            end
182
       end
183
       //---------------------------------------------------------------
184
       // RB from PC-8 (writeback)
185
       //---------------------------------------------------------------
186
       else if (rb_i == rd_wb_i)
187 40 ultra_embe
       begin
188
            result_rb_o = result_wb_i;
189 27 ultra_embe
 
190 36 ultra_embe
            resolved_o  = 1'b1;
191
 
192 27 ultra_embe
`ifdef CONF_CORE_DEBUG
193
            $display(" rB[%d] forwarded 0x%08x (PC-8)", rb_i, result_rb_o);
194
`endif
195
       end
196
   end
197
end
198
 
199
endmodule

powered by: WebSVN 2.1.0

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