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

Subversion Repositories altor32

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

Go to most recent revision | 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
// Copyright (C) 2011 - 2013 Ultra-Embedded.com
14
//
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
    input               mult_lo_ex_i /*verilator public*/,
68
    input               mult_hi_ex_i /*verilator public*/,
69
    input               mult_lo_wb_i /*verilator public*/,
70
    input               mult_hi_wb_i /*verilator public*/,
71
 
72
    // Multiplier result
73
    input [63:0]        result_mult_i /*verilator public*/,
74
 
75
    // Result (EXEC)
76
    input [31:0]        result_ex_i /*verilator public*/,
77
 
78
    // Result (WB)
79
    input [31:0]        result_wb_i /*verilator public*/,
80
 
81
    // Resolved register values
82
    output reg [31:0]   result_ra_o /*verilator public*/,
83
    output reg [31:0]   result_rb_o /*verilator public*/,
84
 
85 36 ultra_embe
    // Result required resolving
86
    output reg          resolved_o /*verilator public*/,
87
 
88 27 ultra_embe
    // Stall due to failed resolve
89
    output reg          stall_o /*verilator public*/
90
);
91
 
92
//-------------------------------------------------------------------
93
// Data forwarding unit
94
//-------------------------------------------------------------------
95
always @ *
96
begin
97
   // Default to no forwarding
98
   result_ra_o  = ra_regval_i;
99
   result_rb_o  = rb_regval_i;
100
   stall_o      = 1'b0;
101 36 ultra_embe
   resolved_o   = 1'b0;
102 27 ultra_embe
 
103
   //---------------------------------------------------------------
104
   // RA - Hazard detection & forwarding
105
   //---------------------------------------------------------------
106
 
107
   // Register[ra] hazard detection & forwarding logic
108
   // (higher priority = latest results!)
109
   if (ra_i != 5'b00000)
110
   begin
111
       //---------------------------------------------------------------
112
       // RA from load (result not ready)
113
       //---------------------------------------------------------------
114
       if (ra_i == rd_load_i & load_pending_i)
115
       begin
116
            stall_o     = 1'b1;
117
`ifdef CONF_CORE_DEBUG
118
            $display(" rA[%d] not ready as load still pending", ra_i);
119
`endif
120
       end
121
       //---------------------------------------------------------------
122
       // RA from PC-4 (exec)
123
       //---------------------------------------------------------------
124
       else if (ra_i == rd_ex_i)
125
       begin
126
            // Multiplier has one cycle latency, stall if needed now
127
            if (mult_lo_ex_i | mult_hi_wb_i)
128
                stall_o     = 1'b1;
129
            else
130
            begin
131
                result_ra_o = result_ex_i;
132 36 ultra_embe
                resolved_o  = 1'b1;
133 27 ultra_embe
`ifdef CONF_CORE_DEBUG
134
                $display(" rA[%d] forwarded 0x%08x (PC-4)", ra_i, result_ra_o);
135
`endif
136
            end
137
       end
138
       //---------------------------------------------------------------
139
       // RA from PC-8 (writeback)
140
       //---------------------------------------------------------------
141
       else if (ra_i == rd_wb_i)
142
       begin
143
            if (mult_hi_wb_i)
144
                result_ra_o = result_mult_i[63:32];
145
            else if (mult_lo_wb_i)
146
                result_ra_o = result_mult_i[31:0];
147
            else
148
                result_ra_o = result_wb_i;
149
 
150 36 ultra_embe
            resolved_o  = 1'b1;
151 27 ultra_embe
`ifdef CONF_CORE_DEBUG
152
            $display(" rA[%d] forwarded 0x%08x (PC-8)", ra_i, result_ra_o);
153
`endif
154
       end
155
   end
156
 
157
   //---------------------------------------------------------------
158
   // RB - Hazard detection & forwarding
159
   //---------------------------------------------------------------       
160
 
161
   // Register[rb] hazard detection & forwarding logic
162
   // (higher priority = latest results!)
163
   if (rb_i != 5'b00000)
164
   begin
165
 
166
       //---------------------------------------------------------------
167
       // RB from load (result not ready)
168
       //---------------------------------------------------------------
169
       if (rb_i == rd_load_i & load_pending_i)
170
       begin
171
            stall_o     = 1'b1;
172
`ifdef CONF_CORE_DEBUG
173
            $display(" rB[%d] not ready as load still pending", rb_i);
174
`endif
175
       end
176
       //---------------------------------------------------------------
177
       // RB from PC-4 (exec)
178
       //---------------------------------------------------------------
179
       else if (rb_i == rd_ex_i)
180
       begin
181
            // Multiplier has one cycle latency, stall if needed now
182
            if (mult_lo_ex_i | mult_hi_wb_i)
183
                stall_o     = 1'b1;
184
            else
185
            begin
186
                result_rb_o = result_ex_i;
187 36 ultra_embe
                resolved_o  = 1'b1;
188 27 ultra_embe
 
189
`ifdef CONF_CORE_DEBUG
190
                $display(" rB[%d] forwarded 0x%08x (PC-4)", rb_i, result_rb_o);
191
`endif
192
            end
193
       end
194
       //---------------------------------------------------------------
195
       // RB from PC-8 (writeback)
196
       //---------------------------------------------------------------
197
       else if (rb_i == rd_wb_i)
198
       begin
199
            if (mult_hi_wb_i)
200
                result_rb_o = result_mult_i[63:32];
201
            else if (mult_lo_wb_i)
202
                result_rb_o = result_mult_i[31:0];
203
            else
204
                result_rb_o = result_wb_i;
205
 
206 36 ultra_embe
            resolved_o  = 1'b1;
207
 
208 27 ultra_embe
`ifdef CONF_CORE_DEBUG
209
            $display(" rB[%d] forwarded 0x%08x (PC-8)", rb_i, result_rb_o);
210
`endif
211
       end
212
   end
213
end
214
 
215
endmodule

powered by: WebSVN 2.1.0

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