1 |
57 |
robfinch |
// ============================================================================
|
2 |
|
|
// __
|
3 |
64 |
robfinch |
// \\__/ o\ (C) 2020-2022 Robert Finch, Waterloo
|
4 |
57 |
robfinch |
// \ __ / All rights reserved.
|
5 |
|
|
// \/_// robfinch@finitron.ca
|
6 |
|
|
// ||
|
7 |
|
|
//
|
8 |
|
|
// DFPAddsub.sv
|
9 |
|
|
//
|
10 |
|
|
// BSD 3-Clause License
|
11 |
|
|
// Redistribution and use in source and binary forms, with or without
|
12 |
|
|
// modification, are permitted provided that the following conditions are met:
|
13 |
|
|
//
|
14 |
|
|
// 1. Redistributions of source code must retain the above copyright notice, this
|
15 |
|
|
// list of conditions and the following disclaimer.
|
16 |
|
|
//
|
17 |
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
18 |
|
|
// this list of conditions and the following disclaimer in the documentation
|
19 |
|
|
// and/or other materials provided with the distribution.
|
20 |
|
|
//
|
21 |
|
|
// 3. Neither the name of the copyright holder nor the names of its
|
22 |
|
|
// contributors may be used to endorse or promote products derived from
|
23 |
|
|
// this software without specific prior written permission.
|
24 |
|
|
//
|
25 |
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
26 |
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
27 |
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
28 |
|
|
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
29 |
|
|
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
30 |
|
|
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
31 |
|
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
32 |
|
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
33 |
|
|
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
34 |
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
35 |
|
|
//
|
36 |
|
|
// ============================================================================
|
37 |
|
|
|
38 |
|
|
import DFPPkg::*;
|
39 |
|
|
|
40 |
|
|
module DFPAddsub128(clk, ce, rm, op, a, b, o);
|
41 |
|
|
input clk;
|
42 |
|
|
input ce;
|
43 |
|
|
input [2:0] rm;
|
44 |
|
|
input op;
|
45 |
|
|
input DFP128 a;
|
46 |
|
|
input DFP128 b;
|
47 |
|
|
output DFP128UD o;
|
48 |
|
|
localparam N=34; // number of BCD digits
|
49 |
64 |
robfinch |
localparam RIP_STAGES = 3;
|
50 |
57 |
robfinch |
|
51 |
|
|
parameter TRUE = 1'b1;
|
52 |
|
|
parameter FALSE = 1'b0;
|
53 |
|
|
|
54 |
|
|
DFP128U au;
|
55 |
|
|
DFP128U bu;
|
56 |
|
|
|
57 |
|
|
DFPUnpack128 u00 (a, au);
|
58 |
|
|
DFPUnpack128 u01 (b, bu);
|
59 |
|
|
|
60 |
64 |
robfinch |
reg [(N+1)*4-1:0] oaa10;
|
61 |
|
|
reg [(N+1)*4-1:0] obb10;
|
62 |
57 |
robfinch |
wire [(N+1)*4-1:0] oss10;
|
63 |
|
|
wire oss10c;
|
64 |
|
|
|
65 |
64 |
robfinch |
BCDAdd8NClk #(.N((N+2)/2)) ubcdadn1
|
66 |
57 |
robfinch |
(
|
67 |
64 |
robfinch |
.clk(clk),
|
68 |
|
|
.a({8'h00,oaa10}),
|
69 |
|
|
.b({8'h00,obb10}),
|
70 |
|
|
.o(oss10),
|
71 |
57 |
robfinch |
.ci(1'b0),
|
72 |
|
|
.co(oss10c)
|
73 |
|
|
);
|
74 |
|
|
|
75 |
|
|
wire [(N+1)*4-1:0] odd10;
|
76 |
|
|
wire odd10c;
|
77 |
|
|
|
78 |
64 |
robfinch |
BCDSub8NClk #(.N((N+2)/2)) ubcdsdn1
|
79 |
57 |
robfinch |
(
|
80 |
64 |
robfinch |
.clk(clk),
|
81 |
|
|
.a({8'h00,oaa10}),
|
82 |
|
|
.b({8'h00,obb10}),
|
83 |
|
|
.o(odd10),
|
84 |
57 |
robfinch |
.ci(1'b0),
|
85 |
|
|
.co(odd10c)
|
86 |
|
|
);
|
87 |
|
|
|
88 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
89 |
|
|
// Clock #1
|
90 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
91 |
|
|
reg op1;
|
92 |
|
|
reg az, bz;
|
93 |
64 |
robfinch |
always_ff @(posedge clk)
|
94 |
57 |
robfinch |
op1 <= op;
|
95 |
64 |
robfinch |
always_ff @(posedge clk)
|
96 |
57 |
robfinch |
az <= au.sig==136'd0 && au.exp==14'd0;
|
97 |
64 |
robfinch |
always_ff @(posedge clk)
|
98 |
57 |
robfinch |
bz <= bu.sig==136'd0 && bu.exp==14'd0;
|
99 |
|
|
|
100 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
101 |
|
|
// Clock #2
|
102 |
|
|
//
|
103 |
|
|
// Figure out which operation is really needed an add or subtract ?
|
104 |
|
|
// If the signs are the same, use the orignal op,
|
105 |
|
|
// otherwise flip the operation
|
106 |
|
|
// a + b = add,+
|
107 |
|
|
// a + -b = sub, so of larger
|
108 |
|
|
// -a + b = sub, so of larger
|
109 |
|
|
// -a + -b = add,-
|
110 |
|
|
// a - b = sub, so of larger
|
111 |
|
|
// a - -b = add,+
|
112 |
|
|
// -a - b = add,-
|
113 |
|
|
// -a - -b = sub, so of larger
|
114 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
115 |
|
|
reg realOp2;
|
116 |
|
|
reg op2;
|
117 |
|
|
reg [15:0] xa2, xb2;
|
118 |
|
|
reg az2, bz2;
|
119 |
|
|
reg xa_gt_xb2;
|
120 |
|
|
reg [N*4-1:0] siga2, sigb2;
|
121 |
|
|
reg sigeq, siga_gt_sigb;
|
122 |
|
|
reg xa_gt_xb2;
|
123 |
|
|
reg expeq;
|
124 |
|
|
reg sxo2;
|
125 |
|
|
|
126 |
64 |
robfinch |
always_ff @(posedge clk)
|
127 |
57 |
robfinch |
if (ce) realOp2 = op1 ^ au.sign ^ bu.sign;
|
128 |
64 |
robfinch |
always_ff @(posedge clk)
|
129 |
57 |
robfinch |
if (ce) op2 <= op1;
|
130 |
64 |
robfinch |
always_ff @(posedge clk)
|
131 |
57 |
robfinch |
if (ce) xa2 <= au.exp;
|
132 |
64 |
robfinch |
always_ff @(posedge clk)
|
133 |
57 |
robfinch |
if (ce) xb2 <= bu.exp;
|
134 |
64 |
robfinch |
always_ff @(posedge clk)
|
135 |
57 |
robfinch |
if (ce) siga2 <= au.sig;
|
136 |
64 |
robfinch |
always_ff @(posedge clk)
|
137 |
57 |
robfinch |
if (ce) sigb2 <= bu.sig;
|
138 |
64 |
robfinch |
always_ff @(posedge clk)
|
139 |
57 |
robfinch |
if (ce) az2 <= az;
|
140 |
64 |
robfinch |
always_ff @(posedge clk)
|
141 |
57 |
robfinch |
if (ce) bz2 <= bz;
|
142 |
64 |
robfinch |
always_ff @(posedge clk)
|
143 |
57 |
robfinch |
if (ce)
|
144 |
|
|
xa_gt_xb2 <= au.exp > bu.exp;
|
145 |
|
|
|
146 |
64 |
robfinch |
always_ff @(posedge clk)
|
147 |
57 |
robfinch |
if (ce) sigeq <= au.sig==bu.sig;
|
148 |
64 |
robfinch |
always_ff @(posedge clk)
|
149 |
57 |
robfinch |
if (ce) siga_gt_sigb <= au.sig > bu.sig;
|
150 |
64 |
robfinch |
always_ff @(posedge clk)
|
151 |
57 |
robfinch |
if (ce) expeq <= au.exp==bu.exp;
|
152 |
|
|
|
153 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
154 |
|
|
// Clock #3
|
155 |
|
|
//
|
156 |
|
|
// Find out if the result will be zero.
|
157 |
|
|
// Determine which fraction to denormalize
|
158 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
159 |
|
|
//
|
160 |
|
|
reg [13:0] xa3, xb3;
|
161 |
|
|
reg resZero3;
|
162 |
|
|
wire xaInf3, xbInf3;
|
163 |
|
|
reg xa_gt_xb3;
|
164 |
|
|
reg a_gt_b3;
|
165 |
|
|
reg op3;
|
166 |
|
|
wire sa3, sb3;
|
167 |
|
|
wire [2:0] rm3;
|
168 |
|
|
reg [N*4-1:0] mfs3;
|
169 |
|
|
|
170 |
64 |
robfinch |
always_ff @(posedge clk)
|
171 |
57 |
robfinch |
if (ce) resZero3 <= (realOp2 & expeq & sigeq) || // subtract, same magnitude
|
172 |
|
|
(az2 & bz2); // both a,b zero
|
173 |
64 |
robfinch |
always_ff @(posedge clk)
|
174 |
57 |
robfinch |
if (ce) xa3 <= xa2;
|
175 |
64 |
robfinch |
always_ff @(posedge clk)
|
176 |
57 |
robfinch |
if (ce) xb3 <= xb2;
|
177 |
64 |
robfinch |
always_ff @(posedge clk)
|
178 |
57 |
robfinch |
if (ce) xa_gt_xb3 <= xa_gt_xb2;
|
179 |
64 |
robfinch |
always_ff @(posedge clk)
|
180 |
57 |
robfinch |
if (ce) a_gt_b3 <= xa_gt_xb2 | (expeq & siga_gt_sigb);
|
181 |
64 |
robfinch |
always_ff @(posedge clk)
|
182 |
57 |
robfinch |
if (ce) op3 <= op2;
|
183 |
64 |
robfinch |
always_ff @(posedge clk)
|
184 |
57 |
robfinch |
if (ce) mfs3 = xa_gt_xb2 ? sigb2 : siga2;
|
185 |
|
|
|
186 |
64 |
robfinch |
ft_delay #(.WID(1), .DEP(2)) udly3c (.clk(clk), .ce(ce), .i(au.sign), .o(sa3));
|
187 |
|
|
ft_delay #(.WID(1), .DEP(2)) udly3d (.clk(clk), .ce(ce), .i(bu.sign), .o(sb3));
|
188 |
|
|
ft_delay #(.WID(3), .DEP(3)) udly3e (.clk(clk), .ce(ce), .i(rm), .o(rm3));
|
189 |
|
|
ft_delay #(.WID(1), .DEP(2)) udly3f (.clk(clk), .ce(ce), .i(aInf), .o(aInf3));
|
190 |
|
|
ft_delay #(.WID(1), .DEP(2)) udly3g (.clk(clk), .ce(ce), .i(bInf), .o(bInf3));
|
191 |
57 |
robfinch |
|
192 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
193 |
|
|
// Clock #4
|
194 |
|
|
//
|
195 |
|
|
// Compute output exponent
|
196 |
|
|
//
|
197 |
|
|
// The output exponent is the larger of the two exponents,
|
198 |
|
|
// unless a subtract operation is in progress and the two
|
199 |
|
|
// numbers are equal, in which case the exponent should be
|
200 |
|
|
// zero.
|
201 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
202 |
|
|
|
203 |
|
|
reg [13:0] xa4, xb4;
|
204 |
|
|
reg [13:0] xo4;
|
205 |
|
|
reg xa_gt_xb4;
|
206 |
|
|
|
207 |
64 |
robfinch |
always_ff @(posedge clk)
|
208 |
57 |
robfinch |
if (ce) xa4 <= xa3;
|
209 |
64 |
robfinch |
always_ff @(posedge clk)
|
210 |
57 |
robfinch |
if (ce) xb4 <= xb3;
|
211 |
64 |
robfinch |
always_ff @(posedge clk)
|
212 |
57 |
robfinch |
if (ce) xo4 <= resZero3 ? 14'd0 : xa_gt_xb3 ? xa3 : xb3;
|
213 |
64 |
robfinch |
always_ff @(posedge clk)
|
214 |
57 |
robfinch |
if (ce) xa_gt_xb4 <= xa_gt_xb3;
|
215 |
|
|
|
216 |
|
|
// Compute output sign
|
217 |
|
|
reg so4;
|
218 |
64 |
robfinch |
always_comb
|
219 |
57 |
robfinch |
case ({resZero3,sa3,op3,sb3}) // synopsys full_case parallel_case
|
220 |
|
|
4'b0000: so4 <= 0; // + + + = +
|
221 |
|
|
4'b0001: so4 <= !a_gt_b3; // + + - = sign of larger
|
222 |
|
|
4'b0010: so4 <= !a_gt_b3; // + - + = sign of larger
|
223 |
|
|
4'b0011: so4 <= 0; // + - - = +
|
224 |
|
|
4'b0100: so4 <= a_gt_b3; // - + + = sign of larger
|
225 |
|
|
4'b0101: so4 <= 1; // - + - = -
|
226 |
|
|
4'b0110: so4 <= 1; // - - + = -
|
227 |
|
|
4'b0111: so4 <= a_gt_b3; // - - - = sign of larger
|
228 |
|
|
4'b1000: so4 <= 0; // A + B, sign = +
|
229 |
|
|
4'b1001: so4 <= (rm3==3'd3); // A + -B, sign = + unless rounding down
|
230 |
|
|
4'b1010: so4 <= (rm3==3'd3); // A - B, sign = + unless rounding down
|
231 |
|
|
4'b1011: so4 <= 0; // A - -B, sign = +
|
232 |
|
|
4'b1100: so4 <= (rm3==3'd3); // -A - -B, sign = + unless rounding down
|
233 |
|
|
4'b1101: so4 <= 1; // -A + -B, sign = -
|
234 |
|
|
4'b1110: so4 <= 1; // -A - +B, sign = -
|
235 |
|
|
4'b1111: so4 <= (rm3==3'd3); // A - B, sign = + unless rounding down
|
236 |
|
|
endcase
|
237 |
|
|
|
238 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
239 |
|
|
// Clock #5
|
240 |
|
|
//
|
241 |
|
|
// Compute the difference in exponents, provides shift amount
|
242 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
243 |
|
|
reg [13:0] xdiff5;
|
244 |
64 |
robfinch |
always_ff @(posedge clk)
|
245 |
57 |
robfinch |
if (ce) xdiff5 <= xa_gt_xb4 ? xa4 - xb4 : xb4 - xa4;
|
246 |
|
|
|
247 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
248 |
|
|
// Clock #6
|
249 |
|
|
//
|
250 |
|
|
// Compute the difference in exponents, provides shift amount
|
251 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
252 |
|
|
// If the difference in the exponent is 24 or greater (assuming 24 nybble dfp or
|
253 |
|
|
// less) then all of the bits will be shifted out to zero. There is no need to
|
254 |
|
|
// keep track of a difference more than 24.
|
255 |
|
|
reg [6:0] xdif6;
|
256 |
|
|
wire [N*4-1:0] mfs6;
|
257 |
64 |
robfinch |
always_ff @(posedge clk)
|
258 |
57 |
robfinch |
if (ce) xdif6 <= xdiff5 > N ? N : xdiff5[6:0];
|
259 |
64 |
robfinch |
ft_delay #(.WID(N*4), .DEP(3)) udly6a (.clk(clk), .ce(ce), .i(mfs3), .o(mfs6));
|
260 |
57 |
robfinch |
|
261 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
262 |
|
|
// Clock #7
|
263 |
|
|
//
|
264 |
|
|
// Determine the sticky bit. The sticky bit is the bitwise or of all the bits
|
265 |
|
|
// being shifted out the right side. The sticky bit is computed here to
|
266 |
|
|
// reduce the number of regs required.
|
267 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
268 |
|
|
reg sticky6;
|
269 |
|
|
wire sticky7;
|
270 |
|
|
wire [7:0] xdif7;
|
271 |
|
|
wire [N*4-1:0] mfs7;
|
272 |
|
|
wire [8:0] xdif6a = {xdif6,2'b00}; // *4
|
273 |
|
|
integer n;
|
274 |
64 |
robfinch |
always @*
|
275 |
|
|
begin
|
276 |
57 |
robfinch |
sticky6 = 1'b0;
|
277 |
|
|
for (n = 0; n < N*4; n = n + 4)
|
278 |
|
|
if (n <= xdif6a)
|
279 |
|
|
sticky6 = sticky6| mfs6[n]|mfs6[n+1]|mfs6[n+2]|mfs6[n+3]; // non-zero nybble
|
280 |
|
|
end
|
281 |
|
|
|
282 |
|
|
// register inputs to shifter and shift
|
283 |
|
|
delay1 #(1) d16(.clk(clk), .ce(ce), .i(sticky6), .o(sticky7) );
|
284 |
|
|
delay1 #(9) d15(.clk(clk), .ce(ce), .i(xdif6a), .o(xdif7) );
|
285 |
|
|
delay1 #(N*4) d14(.clk(clk), .ce(ce), .i(mfs6), .o(mfs7) );
|
286 |
|
|
|
287 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
288 |
|
|
// Clock #8
|
289 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
290 |
|
|
reg [(N+1)*4-1:0] md8;
|
291 |
|
|
wire [N*4-1:0] siga8, sigb8;
|
292 |
|
|
wire xa_gt_xb8;
|
293 |
|
|
wire a_gt_b8;
|
294 |
64 |
robfinch |
always_ff @(posedge clk)
|
295 |
57 |
robfinch |
if (ce) md8 <= ({mfs7,4'b0} >> xdif7)|sticky7; // xdif7 is a multiple of four
|
296 |
|
|
|
297 |
|
|
// sync control signals
|
298 |
64 |
robfinch |
ft_delay #(.WID(1), .DEP(4)) udly8a (.clk(clk), .ce(ce), .i(xa_gt_xb4), .o(xa_gt_xb8));
|
299 |
|
|
ft_delay #(.WID(1), .DEP(5)) udly8b (.clk(clk), .ce(ce), .i(a_gt_b3), .o(a_gt_b8));
|
300 |
|
|
ft_delay #(.WID(N*4), .DEP(6)) udly8d (.clk(clk), .ce(ce), .i(siga2), .o(siga8));
|
301 |
|
|
ft_delay #(.WID(N*4), .DEP(6)) udly8e (.clk(clk), .ce(ce), .i(sigb2), .o(sigb8));
|
302 |
|
|
ft_delay #(.WID(1), .DEP(5)) udly8j (.clk(clk), .ce(ce), .i(op3), .o(op8));
|
303 |
57 |
robfinch |
|
304 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
305 |
|
|
// Clock #9
|
306 |
|
|
// Sort operands and perform add/subtract
|
307 |
|
|
// addition can generate an extra bit, subtract can't go negative
|
308 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
309 |
|
|
reg [(N+1)*4-1:0] oa9, ob9;
|
310 |
|
|
reg a_gt_b9;
|
311 |
64 |
robfinch |
always_ff @(posedge clk)
|
312 |
57 |
robfinch |
if (ce) oa9 <= xa_gt_xb8 ? {siga8,4'b0} : md8;
|
313 |
64 |
robfinch |
always_ff @(posedge clk)
|
314 |
57 |
robfinch |
if (ce) ob9 <= xa_gt_xb8 ? md8 : {sigb8,4'b0};
|
315 |
64 |
robfinch |
always_ff @(posedge clk)
|
316 |
57 |
robfinch |
if (ce) a_gt_b9 <= a_gt_b8;
|
317 |
|
|
|
318 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
319 |
|
|
// Clock #10
|
320 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
321 |
|
|
wire realOp10;
|
322 |
|
|
reg [13:0] xo10;
|
323 |
|
|
|
324 |
64 |
robfinch |
always_ff @(posedge clk)
|
325 |
57 |
robfinch |
if (ce) oaa10 <= a_gt_b9 ? oa9 : ob9;
|
326 |
64 |
robfinch |
always_ff @(posedge clk)
|
327 |
57 |
robfinch |
if (ce) obb10 <= a_gt_b9 ? ob9 : oa9;
|
328 |
64 |
robfinch |
ft_delay #(.WID(1), .DEP(8)) udly10a (.clk(clk), .ce(ce), .i(realOp2), .o(realOp10));
|
329 |
|
|
ft_delay #(.WID(14), .DEP(6)) udly10b (.clk(clk), .ce(ce), .i(xo4), .o(xo10));
|
330 |
57 |
robfinch |
|
331 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
332 |
|
|
// Clock #11
|
333 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
334 |
64 |
robfinch |
wire [(N+1)*4-1:0] mab11;
|
335 |
|
|
wire mab11c;
|
336 |
57 |
robfinch |
wire [N*4-1:0] siga11, sigb11;
|
337 |
|
|
wire abInf11;
|
338 |
|
|
wire aNan11, bNan11;
|
339 |
64 |
robfinch |
wire xoinf11;
|
340 |
57 |
robfinch |
wire op11;
|
341 |
|
|
|
342 |
64 |
robfinch |
ft_delay #(.WID(1), .DEP(8+RIP_STAGES)) udly11a (.clk(clk), .ce(ce), .i(aInf3&bInf3), .o(abInf11));
|
343 |
|
|
ft_delay #(.WID(1), .DEP(10+RIP_STAGES)) udly11c (.clk(clk), .ce(ce), .i(au.nan), .o(aNan11));
|
344 |
|
|
ft_delay #(.WID(1), .DEP(10+RIP_STAGES)) udly11d (.clk(clk), .ce(ce), .i(bu.nan), .o(bNan11));
|
345 |
|
|
ft_delay #(.WID(1), .DEP(3+RIP_STAGES)) udly11e (.clk(clk), .ce(ce), .i(op8), .o(op11));
|
346 |
|
|
ft_delay #(.WID(N*4), .DEP(3+RIP_STAGES)) udly11f (.clk(clk), .ce(ce), .i(siga8), .o(siga11));
|
347 |
|
|
ft_delay #(.WID(N*4), .DEP(3+RIP_STAGES)) udly11g (.clk(clk), .ce(ce), .i(sigb8), .o(sigb11));
|
348 |
|
|
ft_delay #(.WID(1), .DEP(1+RIP_STAGES)) udly11h (.clk(clk), .ce(ce), .i(xo10==14'h2FFF), .o(xoinf11));
|
349 |
|
|
ft_delay #(.WID((N+1)*4+1), .DEP(1+RIP_STAGES)) udly11i (.clk(clk), .ce(ce), .i(realOp10 ? {odd10c,odd10} : {oss10c,oss10}), .o({mab11c,mab11}));
|
350 |
57 |
robfinch |
|
351 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
352 |
64 |
robfinch |
// Clock #12+RIP_STAGES
|
353 |
57 |
robfinch |
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
354 |
|
|
reg [(N+1)*4*2-1:0] mo12; // mantissa output
|
355 |
|
|
reg nan12;
|
356 |
|
|
reg qnan12;
|
357 |
|
|
reg infinity12;
|
358 |
|
|
wire sxo11;
|
359 |
|
|
wire so11;
|
360 |
64 |
robfinch |
ft_delay #(.WID(1), .DEP(9)) udly12a (.clk(clk), .ce(ce), .i(sxo2), .o(sxo11));
|
361 |
|
|
ft_delay #(.WID(1), .DEP(7)) udly12b (.clk(clk), .ce(ce), .i(so4), .o(so11));
|
362 |
57 |
robfinch |
|
363 |
64 |
robfinch |
always_ff @(posedge clk)
|
364 |
57 |
robfinch |
if (ce)
|
365 |
|
|
nan12 <= aNan11|bNan11;
|
366 |
|
|
|
367 |
64 |
robfinch |
always_ff @(posedge clk)
|
368 |
57 |
robfinch |
if (ce) begin
|
369 |
|
|
infinity12 <= 1'b0;
|
370 |
|
|
qnan12 <= 1'b0;
|
371 |
|
|
casez({abInf11,aNan11,bNan11,xoinf11})
|
372 |
|
|
4'b1???: // inf +/- inf - generate QNaN on subtract, inf on add
|
373 |
|
|
if (op11) begin
|
374 |
|
|
mo12 <= {4'h9,{(N+1)*4*2-4{1'd0}}};
|
375 |
|
|
qnan12 <= 1'b1;
|
376 |
|
|
end
|
377 |
|
|
else begin
|
378 |
|
|
mo12 <= {(N+1)*2{4'h9}};
|
379 |
|
|
infinity12 <= 1'b1;
|
380 |
|
|
end
|
381 |
|
|
4'b01??: mo12 <= {4'b0,siga11[107:0],{(N+1)*4{1'd0}}};
|
382 |
|
|
4'b001?: mo12 <= {4'b0,sigb11[107:0],{(N+1)*4{1'd0}}};
|
383 |
|
|
4'b0001: begin mo12 <= {(N+1)*4*2{1'd0}}; infinity12 <= 1'b1; end
|
384 |
|
|
default: mo12 <= {3'b0,mab11c,mab11,{N*4{1'd0}}}; // mab has an extra lead bit and four trailing bits
|
385 |
|
|
endcase
|
386 |
|
|
end
|
387 |
|
|
|
388 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
389 |
|
|
// Clock #13
|
390 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
391 |
|
|
wire so; // sign output
|
392 |
|
|
wire [15:0] xo; // de normalized exponent output
|
393 |
|
|
wire [(N+1)*4*2-1:0] mo; // mantissa output
|
394 |
|
|
|
395 |
64 |
robfinch |
ft_delay #(.WID(1), .DEP(1)) u13c (.clk(clk), .ce(ce), .i(nan12), .o(o.nan) );
|
396 |
|
|
ft_delay #(.WID(1), .DEP(1)) u13d (.clk(clk), .ce(ce), .i(qnan12), .o(o.qnan) );
|
397 |
|
|
ft_delay #(.WID(1), .DEP(1)) u13e (.clk(clk), .ce(ce), .i(infinity12), .o(o.infinity) );
|
398 |
|
|
ft_delay #(.WID(1), .DEP(9)) udly13a (.clk(clk), .ce(ce), .i(so4), .o(o.sign));
|
399 |
|
|
ft_delay #(.WID(14), .DEP(3)) udly13b (.clk(clk), .ce(ce), .i(xo10), .o(o.exp));
|
400 |
|
|
ft_delay #(.WID((N+1)*4*2), .DEP(1)) u13f (.clk(clk), .ce(ce), .i(mo12), .o(o.sig));
|
401 |
|
|
ft_delay #(.WID(1), .DEP(1)) udly13g (.clk(clk), .ce(ce), .i(1'b0), .o(o.snan));
|
402 |
57 |
robfinch |
|
403 |
|
|
endmodule
|
404 |
|
|
|
405 |
|
|
|
406 |
|
|
module DFPAddsub128nr(clk, ce, rm, op, a, b, o);
|
407 |
|
|
input clk; // system clock
|
408 |
|
|
input ce; // core clock enable
|
409 |
|
|
input [2:0] rm; // rounding mode
|
410 |
|
|
input op; // operation 0 = add, 1 = subtract
|
411 |
|
|
input DFP128 a; // operand a
|
412 |
|
|
input DFP128 b; // operand b
|
413 |
|
|
output DFP128 o; // output
|
414 |
|
|
|
415 |
|
|
wire DFP128UD o1;
|
416 |
|
|
wire DFP128UN fpn0;
|
417 |
|
|
|
418 |
|
|
DFPAddsub128 u1 (clk, ce, rm, op, a, b, o1);
|
419 |
|
|
DFPNormalize128 u2(.clk(clk), .ce(ce), .under_i(1'b0), .i(o1), .o(fpn0) );
|
420 |
|
|
DFPRound128 u3(.clk(clk), .ce(ce), .rm(rm), .i(fpn0), .o(o) );
|
421 |
|
|
|
422 |
|
|
endmodule
|