1 |
6 |
davidklun |
/////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// FPU ////
|
4 |
|
|
//// Floating Point Unit (Double precision) ////
|
5 |
|
|
//// ////
|
6 |
|
|
//// Author: David Lundgren ////
|
7 |
|
|
//// davidklun@gmail.com ////
|
8 |
|
|
//// ////
|
9 |
|
|
/////////////////////////////////////////////////////////////////////
|
10 |
|
|
//// ////
|
11 |
|
|
//// Copyright (C) 2009 David Lundgren ////
|
12 |
|
|
//// davidklun@gmail.com ////
|
13 |
|
|
//// ////
|
14 |
|
|
//// This source file may be used and distributed without ////
|
15 |
|
|
//// restriction provided that this copyright statement is not ////
|
16 |
|
|
//// removed from the file and that any derivative work contains ////
|
17 |
|
|
//// the original copyright notice and the associated disclaimer.////
|
18 |
|
|
//// ////
|
19 |
|
|
//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ////
|
20 |
|
|
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
|
21 |
|
|
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
|
22 |
|
|
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
|
23 |
|
|
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ////
|
24 |
|
|
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ////
|
25 |
|
|
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ////
|
26 |
|
|
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ////
|
27 |
|
|
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ////
|
28 |
|
|
//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ////
|
29 |
|
|
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ////
|
30 |
|
|
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ////
|
31 |
|
|
//// POSSIBILITY OF SUCH DAMAGE. ////
|
32 |
|
|
//// ////
|
33 |
|
|
/////////////////////////////////////////////////////////////////////
|
34 |
|
|
|
35 |
8 |
davidklun |
// rmode = 00 (nearest), 01 (to zero), 10 (+ infinity), 11 (- infinity)
|
36 |
|
|
|
37 |
6 |
davidklun |
`timescale 1ns / 100ps
|
38 |
|
|
|
39 |
8 |
davidklun |
module fpu_mul( clk, rst, enable, rmode, opa, opb, ready, outfp);
|
40 |
6 |
davidklun |
input clk;
|
41 |
|
|
input rst;
|
42 |
|
|
input enable;
|
43 |
8 |
davidklun |
input [1:0] rmode;
|
44 |
6 |
davidklun |
input [63:0] opa, opb;
|
45 |
|
|
output ready;
|
46 |
|
|
output [63:0] outfp;
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
reg product_shift;
|
50 |
8 |
davidklun |
reg [1:0] rm_1, rm_2, rm_3, rm_4, rm_5, rm_6, rm_7, rm_8, rm_9;
|
51 |
|
|
reg [1:0] rm_10, rm_11, rm_12, rm_13, rm_14, rm_15;
|
52 |
|
|
reg sign, sign_1, sign_2, sign_3, sign_4, sign_5, sign_6, sign_7, sign_8;
|
53 |
|
|
reg sign_9, sign_10, sign_11, sign_12, sign_13, sign_14, sign_15, sign_16, sign_17;
|
54 |
|
|
reg sign_18, sign_19, sign_20;
|
55 |
6 |
davidklun |
reg [51:0] mantissa_a1, mantissa_a2;
|
56 |
|
|
reg [51:0] mantissa_b1, mantissa_b2;
|
57 |
|
|
reg [10:0] exponent_a;
|
58 |
|
|
reg [10:0] exponent_b;
|
59 |
|
|
reg ready, count_ready, count_ready_0;
|
60 |
|
|
reg [4:0] count;
|
61 |
|
|
reg a_is_zero, b_is_zero, a_is_inf, b_is_inf, in_inf_1, in_inf_2;
|
62 |
|
|
reg in_zero_1;
|
63 |
|
|
reg [11:0] exponent_terms_1, exponent_terms_2, exponent_terms_3, exponent_terms_4;
|
64 |
|
|
reg [11:0] exponent_terms_5, exponent_terms_6, exponent_terms_7;
|
65 |
|
|
reg [11:0] exponent_terms_8, exponent_terms_9;
|
66 |
8 |
davidklun |
reg exponent_gt_expoffset;
|
67 |
6 |
davidklun |
reg [11:0] exponent_1;
|
68 |
|
|
wire [11:0] exponent = 0;
|
69 |
|
|
reg [11:0] exponent_2, exponent_2_0, exponent_2_1;
|
70 |
8 |
davidklun |
reg exponent_gt_prodshift, exponent_is_infinity;
|
71 |
|
|
reg [11:0] exponent_3, exponent_4;
|
72 |
|
|
reg set_mantissa_zero, set_mz_1;
|
73 |
6 |
davidklun |
reg [52:0] mul_a, mul_a1, mul_a2, mul_a3, mul_a4, mul_a5, mul_a6, mul_a7, mul_a8;
|
74 |
|
|
reg [52:0] mul_b, mul_b1, mul_b2, mul_b3, mul_b4, mul_b5, mul_b6, mul_b7, mul_b8;
|
75 |
|
|
reg [40:0] product_a;
|
76 |
|
|
reg [16:0] product_a_2, product_a_3, product_a_4, product_a_5, product_a_6;
|
77 |
|
|
reg [16:0] product_a_7, product_a_8, product_a_9, product_a_10;
|
78 |
|
|
reg [40:0] product_b;
|
79 |
|
|
reg [40:0] product_c;
|
80 |
|
|
reg [25:0] product_d;
|
81 |
|
|
reg [33:0] product_e;
|
82 |
|
|
reg [33:0] product_f;
|
83 |
|
|
reg [35:0] product_g;
|
84 |
|
|
reg [28:0] product_h;
|
85 |
|
|
reg [28:0] product_i;
|
86 |
|
|
reg [30:0] product_j;
|
87 |
|
|
reg [41:0] sum_0;
|
88 |
|
|
reg [6:0] sum_0_2, sum_0_3, sum_0_4, sum_0_5, sum_0_6, sum_0_7, sum_0_8, sum_0_9;
|
89 |
|
|
reg [35:0] sum_1;
|
90 |
|
|
reg [9:0] sum_1_2, sum_1_3, sum_1_4, sum_1_5, sum_1_6, sum_1_7, sum_1_8;
|
91 |
|
|
reg [41:0] sum_2;
|
92 |
|
|
reg [6:0] sum_2_2, sum_2_3, sum_2_4, sum_2_5, sum_2_6, sum_2_7;
|
93 |
|
|
reg [35:0] sum_3;
|
94 |
|
|
reg [36:0] sum_4;
|
95 |
|
|
reg [9:0] sum_4_2, sum_4_3, sum_4_4, sum_4_5;
|
96 |
|
|
reg [27:0] sum_5;
|
97 |
|
|
reg [6:0] sum_5_2, sum_5_3, sum_5_4;
|
98 |
|
|
reg [29:0] sum_6;
|
99 |
|
|
reg [36:0] sum_7;
|
100 |
|
|
reg [16:0] sum_7_2;
|
101 |
|
|
reg [30:0] sum_8;
|
102 |
8 |
davidklun |
reg [105:0] product;
|
103 |
|
|
reg [105:0] product_1;
|
104 |
|
|
reg [52:0] product_2, product_3;
|
105 |
|
|
reg [53:0] product_4, product_5, product_6, product_7;
|
106 |
|
|
reg product_overflow;
|
107 |
|
|
reg [11:0] exponent_5, exponent_6, exponent_7, exponent_8, exponent_9;
|
108 |
|
|
reg round_nearest_mode, round_posinf_mode, round_neginf_mode;
|
109 |
|
|
reg round_nearest_trigger, round_nearest_exception;
|
110 |
|
|
reg round_nearest_enable, round_posinf_trigger, round_posinf_enable;
|
111 |
|
|
reg round_neginf_trigger, round_neginf_enable, round_enable;
|
112 |
|
|
wire [63:0] outfp = { sign, exponent_9[10:0], product_7[51:0]};
|
113 |
6 |
davidklun |
|
114 |
|
|
always @(posedge clk)
|
115 |
|
|
begin
|
116 |
|
|
if (rst) begin
|
117 |
|
|
sign <= 0; sign_1 <= 0; sign_2 <= 0; sign_3 <= 0; sign_4 <= 0;
|
118 |
|
|
sign_5 <= 0; sign_6 <= 0; sign_7 <= 0; sign_8 <= 0; sign_9 <= 0;
|
119 |
|
|
sign_10 <= 0; sign_11 <= 0; sign_12 <= 0; sign_13 <= 0;
|
120 |
8 |
davidklun |
sign_14 <= 0; sign_15 <= 0; sign_16 <= 0; sign_17 <= 0; sign_18 <= 0; sign_19 <= 0;
|
121 |
|
|
sign_20 <= 0; mantissa_a1 <= 0; mantissa_b1 <= 0; mantissa_a2 <= 0; mantissa_b2 <= 0;
|
122 |
|
|
exponent_a <= 0; exponent_b <= 0; rm_1 <= 0; rm_2 <= 0; rm_3 <= 0; rm_4 <= 0; rm_5 <= 0;
|
123 |
|
|
rm_6 <= 0; rm_7 <= 0; rm_8 <= 0; rm_9 <= 0; rm_10 <= 0; rm_11 <= 0;
|
124 |
|
|
rm_12 <= 0; rm_13 <= 0; rm_14 <= 0; rm_15 <= 0;
|
125 |
|
|
a_is_zero <= 0; b_is_zero <= 0; a_is_inf <= 0; b_is_inf <= 0; in_inf_1 <= 0; in_inf_2 <= 0;
|
126 |
|
|
in_zero_1 <= 0; exponent_terms_1 <= 0; exponent_terms_2 <= 0; exponent_terms_3 <= 0;
|
127 |
|
|
exponent_terms_4 <= 0; exponent_terms_5 <= 0; exponent_terms_6 <= 0; exponent_terms_7 <= 0;
|
128 |
|
|
exponent_terms_8 <= 0; exponent_terms_9 <= 0; exponent_gt_expoffset <= 0; exponent_1 <= 0;
|
129 |
6 |
davidklun |
exponent_2_0 <= 0; exponent_2_1 <= 0; exponent_2 <= 0; exponent_gt_prodshift <= 0;
|
130 |
8 |
davidklun |
exponent_is_infinity <= 0; exponent_3 <= 0; exponent_4 <= 0;
|
131 |
|
|
set_mantissa_zero <= 0; set_mz_1 <= 0; mul_a <= 0; mul_b <= 0; mul_a1 <= 0; mul_b1 <= 0;
|
132 |
|
|
mul_a2 <= 0; mul_b2 <= 0; mul_a3 <= 0; mul_b3 <= 0; mul_a4 <= 0; mul_b4 <= 0; mul_a5 <= 0;
|
133 |
|
|
mul_b5 <= 0; mul_a6 <= 0; mul_b6 <= 0; mul_a7 <= 0; mul_b7 <= 0; mul_a8 <= 0; mul_b8 <= 0;
|
134 |
6 |
davidklun |
product_a <= 0; product_a_2 <= 0; product_a_3 <= 0; product_a_4 <= 0; product_a_5 <= 0;
|
135 |
|
|
product_a_6 <= 0; product_a_7 <= 0; product_a_8 <= 0; product_a_9 <= 0; product_a_10 <= 0;
|
136 |
|
|
product_b <= 0; product_c <= 0; product_d <= 0; product_e <= 0; product_f <= 0;
|
137 |
|
|
product_g <= 0; product_h <= 0; product_i <= 0; product_j <= 0;
|
138 |
|
|
sum_0 <= 0; sum_0_2 <= 0; sum_0_3 <= 0; sum_0_4 <= 0; sum_0_5 <= 0; sum_0_6 <= 0;
|
139 |
8 |
davidklun |
sum_0_7 <= 0; sum_0_8 <= 0; sum_0_9 <= 0; sum_1 <= 0; sum_1_2 <= 0; sum_1_3 <= 0; sum_1_4 <= 0;
|
140 |
|
|
sum_1_5 <= 0; sum_1_6 <= 0; sum_1_7 <= 0; sum_1_8 <= 0; sum_2 <= 0; sum_2_2 <= 0; sum_2_3 <= 0;
|
141 |
|
|
sum_2_4 <= 0; sum_2_5 <= 0; sum_2_6 <= 0; sum_2_7 <= 0; sum_3 <= 0; sum_4 <= 0; sum_4_2 <= 0;
|
142 |
|
|
sum_4_3 <= 0; sum_4_4 <= 0; sum_4_5 <= 0; sum_5 <= 0; sum_5_2 <= 0; sum_5_3 <= 0; sum_5_4 <= 0;
|
143 |
|
|
sum_6 <= 0; sum_7 <= 0; sum_7_2 <= 0; sum_8 <= 0; product <= 0; product_1 <= 0; product_2 <= 0;
|
144 |
|
|
product_3 <= 0; product_4 <= 0; product_5 <= 0; product_overflow <= 0; product_6 <= 0;
|
145 |
|
|
exponent_5 <= 0; exponent_6 <= 0; exponent_7 <= 0; exponent_8 <= 0; product_shift <= 0;
|
146 |
|
|
product_7 <= 0; exponent_9 <= 0;
|
147 |
|
|
round_nearest_mode <= 0; round_posinf_mode <= 0; round_neginf_mode <= 0; round_nearest_trigger <= 0;
|
148 |
|
|
round_nearest_exception <= 0; round_nearest_enable <= 0; round_posinf_trigger <= 0; round_posinf_enable <= 0;
|
149 |
|
|
round_neginf_trigger <= 0; round_neginf_enable <= 0; round_enable <= 0;
|
150 |
6 |
davidklun |
end
|
151 |
|
|
else if (enable) begin
|
152 |
|
|
sign_1 <= opa[63] ^ opb[63]; sign_2 <= sign_1; sign_3 <= sign_2; sign_4 <= sign_3;
|
153 |
|
|
sign_5 <= sign_4; sign_6 <= sign_5; sign_7 <= sign_6; sign_8 <= sign_7; sign_9 <= sign_8;
|
154 |
|
|
sign_10 <= sign_9; sign_11 <= sign_10; sign_12 <= sign_11; sign_13 <= sign_12;
|
155 |
8 |
davidklun |
sign_14 <= sign_13; sign_15 <= sign_14; sign_16 <= sign_15; sign_17 <= sign_16;
|
156 |
|
|
sign_18 <= sign_17; sign_19 <= sign_18; sign_20 <= sign_19; sign <= sign_20;
|
157 |
|
|
mantissa_a1 <= opa[51:0]; mantissa_b1 <= opb[51:0]; mantissa_a2 <= mantissa_a1;
|
158 |
|
|
mantissa_b2 <= mantissa_b1; exponent_a <= opa[62:52]; exponent_b <= opb[62:52];
|
159 |
|
|
rm_1 <= rmode; rm_2 <= rm_1; rm_3 <= rm_2; rm_4 <= rm_3;
|
160 |
|
|
rm_5 <= rm_4; rm_6 <= rm_5; rm_7 <= rm_6; rm_8 <= rm_7; rm_9 <= rm_8;
|
161 |
|
|
rm_10 <= rm_9; rm_11 <= rm_10; rm_12 <= rm_11; rm_13 <= rm_12; rm_14 <= rm_13;
|
162 |
|
|
rm_15 <= rm_14;
|
163 |
|
|
a_is_zero <= !(|exponent_a); b_is_zero <= !(|exponent_b);
|
164 |
|
|
a_is_inf <= exponent_a == 2047; b_is_inf <= exponent_b == 2047;
|
165 |
|
|
in_inf_1 <= a_is_inf | b_is_inf; in_inf_2 <= in_inf_1;
|
166 |
6 |
davidklun |
in_zero_1 <= a_is_zero | b_is_zero;
|
167 |
|
|
exponent_terms_1 <= exponent_a + exponent_b;
|
168 |
|
|
exponent_terms_2 <= exponent_terms_1;
|
169 |
|
|
exponent_terms_3 <= in_zero_1 ? 12'b0 : exponent_terms_2;
|
170 |
|
|
exponent_terms_4 <= in_inf_2 ? 12'b110000000000 : exponent_terms_3;
|
171 |
8 |
davidklun |
exponent_terms_5 <= exponent_terms_4; exponent_terms_6 <= exponent_terms_5;
|
172 |
|
|
exponent_terms_7 <= exponent_terms_6; exponent_terms_8 <= exponent_terms_7;
|
173 |
6 |
davidklun |
exponent_terms_9 <= exponent_terms_8;
|
174 |
|
|
exponent_gt_expoffset <= exponent_terms_9 > 1022;
|
175 |
|
|
exponent_1 <= exponent_terms_9 - 1022;
|
176 |
|
|
exponent_2_0 <= exponent_gt_expoffset ? exponent_1 : exponent;
|
177 |
|
|
exponent_2_1 <= exponent_2_0;
|
178 |
|
|
exponent_2 <= exponent_2_1;
|
179 |
8 |
davidklun |
exponent_is_infinity <= (exponent_3 > 2046) & exponent_gt_prodshift;
|
180 |
6 |
davidklun |
exponent_3 <= exponent_2 - product_shift;
|
181 |
|
|
exponent_gt_prodshift <= exponent_2 >= product_shift;
|
182 |
|
|
exponent_4 <= exponent_gt_prodshift ? exponent_3 : exponent;
|
183 |
8 |
davidklun |
exponent_5 <= exponent_is_infinity ? 12'b011111111111 : exponent_4;
|
184 |
|
|
set_mantissa_zero <= exponent_4 == 0 | exponent_is_infinity;
|
185 |
|
|
set_mz_1 <= set_mantissa_zero;
|
186 |
6 |
davidklun |
exponent_6 <= exponent_5;
|
187 |
8 |
davidklun |
mul_a <= { !a_is_zero, mantissa_a2 }; mul_b <= { !b_is_zero, mantissa_b2 };
|
188 |
6 |
davidklun |
mul_a1 <= mul_a; mul_b1 <= mul_b;
|
189 |
|
|
mul_a2 <= mul_a1; mul_b2 <= mul_b1; mul_a3 <= mul_a2; mul_b3 <= mul_b2;
|
190 |
|
|
mul_a4 <= mul_a3; mul_b4 <= mul_b3; mul_a5 <= mul_a4; mul_b5 <= mul_b4;
|
191 |
|
|
mul_a6 <= mul_a5; mul_b6 <= mul_b5; mul_a7 <= mul_a6; mul_b7 <= mul_b6;
|
192 |
|
|
mul_a8 <= mul_a7; mul_b8 <= mul_b7;
|
193 |
|
|
product_a <= mul_a[23:0] * mul_b[16:0]; product_a_2 <= product_a[16:0];
|
194 |
|
|
product_a_3 <= product_a_2; product_a_4 <= product_a_3; product_a_5 <= product_a_4;
|
195 |
|
|
product_a_6 <= product_a_5; product_a_7 <= product_a_6; product_a_8 <= product_a_7;
|
196 |
|
|
product_a_9 <= product_a_8; product_a_10 <= product_a_9;
|
197 |
|
|
product_b <= mul_a[23:0] * mul_b[33:17];
|
198 |
|
|
product_c <= mul_a2[23:0] * mul_b2[50:34];
|
199 |
|
|
product_d <= mul_a5[23:0] * mul_b5[52:51];
|
200 |
|
|
product_e <= mul_a1[40:24] * mul_b1[16:0];
|
201 |
|
|
product_f <= mul_a4[40:24] * mul_b4[33:17];
|
202 |
|
|
product_g <= mul_a7[40:24] * mul_b7[52:34];
|
203 |
|
|
product_h <= mul_a3[52:41] * mul_b3[16:0];
|
204 |
|
|
product_i <= mul_a6[52:41] * mul_b6[33:17];
|
205 |
|
|
product_j <= mul_a8[52:41] * mul_b8[52:34];
|
206 |
|
|
sum_0 <= product_a[40:17] + product_b; sum_0_2 <= sum_0[6:0]; sum_0_3 <= sum_0_2;
|
207 |
|
|
sum_0_4 <= sum_0_3; sum_0_5 <= sum_0_4; sum_0_6 <= sum_0_5; sum_0_7 <= sum_0_6;
|
208 |
|
|
sum_0_8 <= sum_0_7; sum_0_9 <= sum_0_8;
|
209 |
|
|
sum_1 <= sum_0[41:7] + product_e; sum_1_2 <= sum_1[9:0]; sum_1_3 <= sum_1_2;
|
210 |
|
|
sum_1_4 <= sum_1_3; sum_1_5 <= sum_1_4; sum_1_6 <= sum_1_5; sum_1_7 <= sum_1_6;
|
211 |
|
|
sum_1_8 <= sum_1_7;
|
212 |
|
|
sum_2 <= sum_1[35:10] + product_c; sum_2_2 <= sum_2[6:0]; sum_2_3 <= sum_2_2;
|
213 |
|
|
sum_2_4 <= sum_2_3; sum_2_5 <= sum_2_4; sum_2_6 <= sum_2_5; sum_2_7 <= sum_2_6;
|
214 |
|
|
sum_3 <= sum_2[41:7] + product_h;
|
215 |
|
|
sum_4 <= sum_3 + product_f; sum_4_2 <= sum_4[9:0]; sum_4_3 <= sum_4_2;
|
216 |
|
|
sum_4_4 <= sum_4_3; sum_4_5 <= sum_4_4;
|
217 |
|
|
sum_5 <= sum_4[36:10] + product_d; sum_5_2 <= sum_5[6:0];
|
218 |
|
|
sum_5_3 <= sum_5_2; sum_5_4 <= sum_5_3;
|
219 |
|
|
sum_6 <= sum_5[27:7] + product_i;
|
220 |
|
|
sum_7 <= sum_6 + product_g; sum_7_2 <= sum_7[16:0];
|
221 |
|
|
sum_8 <= sum_7[36:17] + product_j;
|
222 |
|
|
product <= { sum_8, sum_7_2[16:0], sum_5_4[6:0], sum_4_5[9:0], sum_2_7[6:0],
|
223 |
|
|
sum_1_8[9:0], sum_0_9[6:0], product_a_10[16:0] };
|
224 |
|
|
product_1 <= product << product_shift;
|
225 |
8 |
davidklun |
product_2 <= product_1[105:53]; product_3 <= product_2;
|
226 |
|
|
product_4 <= set_mantissa_zero ? 54'b0 : { 1'b0, product_3};
|
227 |
6 |
davidklun |
product_shift <= !sum_8[30];
|
228 |
8 |
davidklun |
round_nearest_mode <= rm_15 == 2'b00;
|
229 |
|
|
round_posinf_mode <= rm_15 == 2'b10;
|
230 |
|
|
round_neginf_mode <= rm_15 == 2'b11;
|
231 |
|
|
round_nearest_trigger <= product_1[52];
|
232 |
|
|
round_nearest_exception <= !(|product_1[51:0]) & (product_1[53] == 0);
|
233 |
|
|
round_nearest_enable <= round_nearest_mode & round_nearest_trigger & !round_nearest_exception;
|
234 |
|
|
round_posinf_trigger <= |product_1[52:0] & !sign_15;
|
235 |
|
|
round_posinf_enable <= round_posinf_mode & round_posinf_trigger;
|
236 |
|
|
round_neginf_trigger <= |product_1[52:0] & sign_15;
|
237 |
|
|
round_neginf_enable <= round_neginf_mode & round_neginf_trigger;
|
238 |
|
|
round_enable <= round_posinf_enable | round_neginf_enable | round_nearest_enable;
|
239 |
|
|
product_5 <= round_enable & !set_mz_1 ? product_4 + 1 : product_4;
|
240 |
|
|
product_overflow <= product_5[53];
|
241 |
|
|
product_6 <= product_5;
|
242 |
|
|
product_7 <= product_overflow ? product_6 >> 1 : product_6;
|
243 |
|
|
exponent_7 <= exponent_6; exponent_8 <= exponent_7;
|
244 |
|
|
exponent_9 <= product_overflow ? exponent_8 + 1 : exponent_8;
|
245 |
6 |
davidklun |
end
|
246 |
|
|
end
|
247 |
|
|
|
248 |
|
|
always @(posedge clk)
|
249 |
|
|
begin
|
250 |
|
|
if (rst) begin
|
251 |
|
|
ready <= 0;
|
252 |
|
|
count_ready_0 <= 0;
|
253 |
|
|
count_ready <= 0;
|
254 |
|
|
end
|
255 |
|
|
else if (enable) begin
|
256 |
|
|
ready <= count_ready;
|
257 |
8 |
davidklun |
count_ready_0 <= count == 18;
|
258 |
|
|
count_ready <= count == 19;
|
259 |
6 |
davidklun |
end
|
260 |
|
|
end
|
261 |
|
|
|
262 |
|
|
always @(posedge clk)
|
263 |
|
|
begin
|
264 |
|
|
if (rst)
|
265 |
|
|
count <= 0;
|
266 |
|
|
else if (enable & !count_ready_0 & !count_ready)
|
267 |
|
|
count <= count + 1;
|
268 |
|
|
end
|
269 |
|
|
|
270 |
|
|
endmodule
|