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

Subversion Repositories altor32

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

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

powered by: WebSVN 2.1.0

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