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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [fpFMA32combo.sv] - Blame information for rev 74

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 74 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2019-2022  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
//      fpFMA32combo.sv
9
//              - floating point fused multiplier + adder
10
//              - combinational logic only
11
//              - IEEE 754 representation
12
//
13
//
14
// BSD 3-Clause License
15
// Redistribution and use in source and binary forms, with or without
16
// modification, are permitted provided that the following conditions are met:
17
//
18
// 1. Redistributions of source code must retain the above copyright notice, this
19
//    list of conditions and the following disclaimer.
20
//
21
// 2. Redistributions in binary form must reproduce the above copyright notice,
22
//    this list of conditions and the following disclaimer in the documentation
23
//    and/or other materials provided with the distribution.
24
//
25
// 3. Neither the name of the copyright holder nor the names of its
26
//    contributors may be used to endorse or promote products derived from
27
//    this software without specific prior written permission.
28
//
29
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
33
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
//
40
// ============================================================================
41
 
42
import fp32Pkg::*;
43
 
44
module fpFMA32combo (op, rm, a, b, c, o, under, over, inf, zero);
45
input op;               // operation 0 = add, 1 = subtract
46
input [2:0] rm;
47
input  FP32 a, b, c;
48
output FP32X o;
49
output under;
50
output over;
51
output inf;
52
output zero;
53
 
54
// constants
55
wire [fp32Pkg::EMSB:0] infXp = {fp32Pkg::EMSB+1{1'b1}}; // infinite / NaN - all ones
56
// The following is the value for an exponent of zero, with the offset
57
// eg. 8'h7f for eight bit exponent, 11'h7ff for eleven bit exponent, etc.
58
wire [fp32Pkg::EMSB:0] bias = {1'b0,{fp32Pkg::EMSB{1'b1}}};     //2^0 exponent
59
// The following is a template for a quiet nan. (MSB=1)
60
wire [fp32Pkg::FMSB:0] qNaN  = {1'b1,{fp32Pkg::FMSB{1'b0}}};
61
 
62
// -----------------------------------------------------------
63
// Clock #1
64
// - decode the input operands
65
// - derive basic information
66
// -----------------------------------------------------------
67
 
68
wire sa1, sb1, sc1;                     // sign bit
69
wire [fp32Pkg::EMSB:0] xa1, xb1, xc1;   // exponent bits
70
wire [fp32Pkg::FMSB+1:0] fracta1, fractb1, fractc1;     // includes unhidden bit
71
wire a_dn1, b_dn1, c_dn1;                       // a/b is denormalized
72
wire aNan1, bNan1, cNan1;
73
wire az1, bz1, cz1;
74
wire aInf1, bInf1, cInf1;
75
reg op1;
76
 
77
fpDecomp32 u1a (.i(a), .sgn(sa1), .exp(xa1), .fract(fracta1), .xz(a_dn1), .vz(az1), .inf(aInf1), .nan(aNan1) );
78
fpDecomp32 u1b (.i(b), .sgn(sb1), .exp(xb1), .fract(fractb1), .xz(b_dn1), .vz(bz1), .inf(bInf1), .nan(bNan1) );
79
fpDecomp32 u1c (.i(c), .sgn(sc1), .exp(xc1), .fract(fractc1), .xz(c_dn1), .vz(cz1), .inf(cInf1), .nan(cNan1) );
80
 
81
always_comb
82
        op1 <= op;
83
 
84
// -----------------------------------------------------------
85
// Clock #2
86
// Compute the sum of the exponents.
87
// correct the exponent for denormalized operands
88
// adjust the sum by the exponent offset (subtract 127)
89
// mul: ex1 = xa + xb,  result should always be < 1ffh
90
// Form partial products (clocks 2 to 5)
91
// -----------------------------------------------------------
92
 
93
reg abz2;
94
reg [fp32Pkg::EMSB+2:0] ex2;
95
reg [fp32Pkg::EMSB:0] xc2;
96
reg realOp2;
97
reg xcInf2;
98
 
99
always_comb
100
        abz2 <= az1|bz1;
101
always_comb
102
        ex2 <= (xa1|(a_dn1&~az1)) + (xb1|(b_dn1&~bz1)) - bias;
103
always_comb
104
        xc2 <= (xc1|(c_dn1&~cz1));
105
always_comb
106
        xcInf2 = &xc1;
107
 
108
// Figure out which operation is really needed an add or
109
// subtract ?
110
// If the signs are the same, use the orignal op,
111
// otherwise flip the operation
112
//  a +  b = add,+
113
//  a + -b = sub, so of larger
114
// -a +  b = sub, so of larger
115
// -a + -b = add,-
116
//  a -  b = sub, so of larger
117
//  a - -b = add,+
118
// -a -  b = add,-
119
// -a - -b = sub, so of larger
120
always_comb
121
        realOp2 <= (sa1 ^ sb1) ^ sc1 ? ~op1 : op1;
122
 
123
reg [fp32Pkg::FX:0] fract5;
124
wire [63:0] fractoo;
125
mult32x32combo umul1 (.a({9'd0,fracta1}), .b({9'd0,fractb1}), .o(fractoo));
126
always_comb
127
  fract5 <= fractoo[fp32Pkg::FX:0];
128
 
129
// -----------------------------------------------------------
130
// Clock #3
131
// Select zero exponent
132
// -----------------------------------------------------------
133
 
134
reg [fp32Pkg::EMSB+2:0] ex3;
135
reg [fp32Pkg::EMSB:0] xc3;
136
always_comb
137
        ex3 <= abz2 ? 1'd0 : ex2;
138
always_comb
139
        xc3 <= xc2;
140
 
141
// -----------------------------------------------------------
142
// Clock #4
143
// Generate partial products.
144
// -----------------------------------------------------------
145
 
146
reg [fp32Pkg::EMSB+2:0] ex4;
147
reg [fp32Pkg::EMSB:0] xc4;
148
 
149
always_comb
150
        ex4 <= ex3;
151
always_comb
152
        xc4 <= xc3;
153
 
154
// -----------------------------------------------------------
155
// Clock #5
156
// Sum partial products (above)
157
// compute multiplier overflow and underflow
158
// -----------------------------------------------------------
159
 
160
// Status
161
reg under5;
162
reg over5;
163
reg [fp32Pkg::EMSB+2:0] ex5;
164
reg [fp32Pkg::EMSB:0] xc5;
165
reg aInf5, bInf5;
166
reg aNan5, bNan5;
167
reg qNaNOut5;
168
 
169
always_comb
170
        under5 <= ex4[fp32Pkg::EMSB+2];
171
always_comb
172
        over5 <= (&ex4[fp32Pkg::EMSB:0] | ex4[fp32Pkg::EMSB+1]) & !ex4[fp32Pkg::EMSB+2];
173
always_comb
174
        ex5 <= ex4;
175
always_comb
176
        xc5 <= xc4;
177
always_comb
178
        aInf5 <= aInf1;
179
always_comb
180
        bInf5 <= bInf1;
181
 
182
// determine when a NaN is output
183
reg [fp32Pkg::MSB:0] a5,b5;
184
always_comb
185
        qNaNOut5 <= (aInf1&bz1)|(bInf1&az1);
186
always_comb
187
        aNan5 <= aNan1;
188
always_comb
189
        bNan5 <= bNan1;
190
always_comb
191
        a5 <= a;
192
always_comb
193
        b5 <= b;
194
 
195
// -----------------------------------------------------------
196
// Clock #6
197
// - figure multiplier mantissa output
198
// - figure multiplier exponent output
199
// - correct xponent and mantissa for exceptional conditions
200
// -----------------------------------------------------------
201
 
202
reg [fp32Pkg::FX:0] mo6;
203
reg [fp32Pkg::EMSB+2:0] ex6;
204
reg [fp32Pkg::EMSB:0] xc6;
205
reg [fp32Pkg::FMSB+1:0] fractc6;
206
reg under6;
207
always_comb
208
        fractc6 <= fractc1;
209
always_comb
210
        under6 <= under5;
211
 
212
always_comb
213
         xc6 <= xc5;
214
 
215
always_comb
216
        casez({aNan5,bNan5,qNaNOut5,aInf5,bInf5,over5})
217
        6'b1?????:  mo6 <= {1'b1,1'b1,a5[fp32Pkg::FMSB-1:0],{fp32Pkg::FMSB+1{1'b0}}};
218
  6'b01????:  mo6 <= {1'b1,1'b1,b5[fp32Pkg::FMSB-1:0],{fp32Pkg::FMSB+1{1'b0}}};
219
        6'b001???:      mo6 <= {1'b1,qNaN|3'd4,{fp32Pkg::FMSB+1{1'b0}}};        // multiply inf * zero
220
        6'b0001??:      mo6 <= 0;       // mul inf's
221
        6'b00001?:      mo6 <= 0;       // mul inf's
222
        6'b000001:      mo6 <= 0;       // mul overflow
223
        default:        mo6 <= fract5;
224
        endcase
225
 
226
always_comb
227
        casez({qNaNOut5|aNan5|bNan5,aInf5,bInf5,over5,under5})
228
        5'b1????:       ex6 <= infXp;   // qNaN - infinity * zero
229
        5'b01???:       ex6 <= infXp;   // 'a' infinite
230
        5'b001??:       ex6 <= infXp;   // 'b' infinite
231
        5'b0001?:       ex6 <= infXp;   // result overflow
232
        5'b00001:       ex6 <= ex5;             //0;            // underflow
233
        default:        ex6 <= ex5;             // situation normal
234
        endcase
235
 
236
// -----------------------------------------------------------
237
// Clock #7
238
// - prep for addition, determine greater operand
239
// -----------------------------------------------------------
240
reg ex_gt_xc7;
241
reg xeq7;
242
reg ma_gt_mc7;
243
reg meq7;
244
reg az7, bz7, cz7;
245
reg realOp7;
246
 
247
// which has greater magnitude ? Used for sign calc
248
always_comb
249
        ex_gt_xc7 <= xc6=='d0 ? |ex6 : $signed(ex6) > $signed({2'b0,xc6});
250
always_comb
251
        xeq7 <= (ex6=={2'b0,xc6});
252
always_comb
253
        ma_gt_mc7 <= mo6 > {fractc6,{fp32Pkg::FMSB+1{1'b0}}};
254
always_comb
255
        meq7 <= mo6 == {fractc6,{fp32Pkg::FMSB+1{1'b0}}};
256
always_comb
257
        az7 <= az1;
258
always_comb
259
        bz7 <= bz1;
260
always_comb
261
        cz7 <= cz1;
262
always_comb
263
        realOp7 <= realOp2;
264
 
265
// -----------------------------------------------------------
266
// Clock #8
267
// - prep for addition, determine greater operand
268
// - determine if result will be zero
269
// -----------------------------------------------------------
270
 
271
reg a_gt_b8;
272
reg resZero8;
273
reg ex_gt_xc8;
274
reg [fp32Pkg::EMSB+2:0] ex8;
275
reg [fp32Pkg::EMSB:0] xc8;
276
reg xcInf8;
277
reg [2:0] rm8;
278
reg op8;
279
reg sa8, sc8;
280
 
281
always_comb
282
        ex8 <= ex6;
283
always_comb
284
        xc8 <= xc6;
285
always_comb
286
        xcInf8 <= xcInf2;
287
always_comb
288
        rm8 <= rm;
289
always_comb
290
        op8 <= op1;
291
always_comb
292
        sa8 <= sa1 ^ sb1;
293
always_comb
294
        sc8 <= sc1;
295
 
296
always_comb
297
        ex_gt_xc8 <= ex_gt_xc7;
298
always_comb
299
        a_gt_b8 <= ex_gt_xc7 || (xeq7 && ma_gt_mc7);
300
 
301
// Find out if the result will be zero.
302
always_comb
303
        resZero8 <= (realOp7 & xeq7 & meq7) ||  // subtract, same magnitude
304
                           ((az7 | bz7) & cz7);               // a or b zero and c zero
305
 
306
// -----------------------------------------------------------
307
// CLock #9
308
// Compute output exponent and sign
309
//
310
// The output exponent is the larger of the two exponents,
311
// unless a subtract operation is in progress and the two
312
// numbers are equal, in which case the exponent should be
313
// zero.
314
// -----------------------------------------------------------
315
 
316
reg so9;
317
reg [fp32Pkg::EMSB+2:0] ex9;
318
reg [fp32Pkg::EMSB+2:0] ex9a;
319
reg ex_gt_xc9;
320
reg [fp32Pkg::EMSB:0] xc9;
321
reg a_gt_c9;
322
reg [fp32Pkg::FX:0] mo9;
323
reg [fp32Pkg::FMSB+1:0] fractc9;
324
reg under9;
325
reg xeq9;
326
 
327
always_comb
328
         ex_gt_xc9 <= ex_gt_xc8;
329
always_comb
330
         a_gt_c9 <= a_gt_b8;
331
always_comb
332
         xc9 <= xc8;
333
always_comb
334
         ex9a <= ex8;
335
always_comb
336
        mo9 <= mo6;
337
always_comb
338
        fractc9 <= fractc6;
339
always_comb
340
        under9 <= under6;
341
always_comb
342
        xeq9 <= xeq7;
343
 
344
always_comb
345
        ex9 <= resZero8 ? 1'd0 : ex_gt_xc8 ? ex8 : {2'b0,xc8};
346
 
347
// Compute output sign
348
always_comb
349
        case ({resZero8,sa8,op8,sc8})   // synopsys full_case parallel_case
350
        4'b0000: so9 <= 0;                      // + + + = +
351
        4'b0001: so9 <= !a_gt_b8;       // + + - = sign of larger
352
        4'b0010: so9 <= !a_gt_b8;       // + - + = sign of larger
353
        4'b0011: so9 <= 0;                      // + - - = +
354
        4'b0100: so9 <= a_gt_b8;                // - + + = sign of larger
355
        4'b0101: so9 <= 1;                      // - + - = -
356
        4'b0110: so9 <= 1;                      // - - + = -
357
        4'b0111: so9 <= a_gt_b8;                // - - - = sign of larger
358
        4'b1000: so9 <= 0;                      //  A +  B, sign = +
359
        4'b1001: so9 <= rm8==3;         //  A + -B, sign = + unless rounding down
360
        4'b1010: so9 <= rm8==3;         //  A -  B, sign = + unless rounding down
361
        4'b1011: so9 <= 0;                      // +A - -B, sign = +
362
        4'b1100: so9 <= rm8==3;         // -A +  B, sign = + unless rounding down
363
        4'b1101: so9 <= 1;                      // -A + -B, sign = -
364
        4'b1110: so9 <= 1;                      // -A - +B, sign = -
365
        4'b1111: so9 <= rm8==3;         // -A - -B, sign = + unless rounding down
366
        endcase
367
 
368
// -----------------------------------------------------------
369
// Clock #10
370
// Compute the difference in exponents, provides shift amount
371
// Note that ex9a will be negative for an underflow condition
372
// so it's added rather than subtracted from xc9 as -(-num)
373
// is the same as an add. The underflow is tracked rather than
374
// using extra bits in the exponent.
375
// -----------------------------------------------------------
376
reg [fp32Pkg::EMSB+2:0] xdiff10;
377
reg [fp32Pkg::FX:0] mfs;
378
reg ops10;
379
 
380
// If the multiplier exponent was negative (underflowed) then
381
// the mantissa needs to be shifted right even more (until
382
// the exponent is zero. The total shift would be xc9-0-
383
// amount underflows which is xc9 + -ex9a.
384
 
385
always_comb
386
        xdiff10 <= ex_gt_xc9 ? ex9a - xc9
387
                                                                                : ex9a[fp32Pkg::EMSB+2] ? xc9 + (~ex9a+2'd1)
388
                                                                                : xc9 - ex9a;
389
 
390
// Determine which fraction to denormalize (the one with the
391
// smaller exponent is denormalized). If the exponents are equal
392
// denormalize the smaller fraction.
393
always_comb
394
        mfs <=
395
                xeq9 ? (a_gt_c9 ? {4'b0,fractc9,{fp32Pkg::FMSB+1{1'b0}}} : mo9)
396
                 : ex_gt_xc9 ? {4'b0,fractc9,{fp32Pkg::FMSB+1{1'b0}}} : mo9;
397
 
398
always_comb
399
        ops10 <= xeq9 ? (a_gt_c9 ? 1'b1 : 1'b0)
400
                                                                                                : (ex_gt_xc9 ? 1'b1 : 1'b0);
401
 
402
// -----------------------------------------------------------
403
// Clock #11
404
// Limit the size of the shifter to only bits needed.
405
// -----------------------------------------------------------
406
reg [7:0] xdif11;
407
 
408
always_comb
409
        xdif11 <= xdiff10 > fp32Pkg::FX+3 ? fp32Pkg::FX+3 : xdiff10;
410
 
411
// -----------------------------------------------------------
412
// Clock #12
413
// Determine the sticky bit
414
// -----------------------------------------------------------
415
 
416
wire sticky;
417
reg sticky12;
418
reg [fp32Pkg::FX:0] mfs12;
419
reg [7:0] xdif12;
420
 
421
redorN #(.BSIZE(fp32Pkg::FX+1)) uredor1 (.a({1'b0,xdif11+fp32Pkg::FMSB}), .b(mfs), .o(sticky));
422
/*
423
generate
424
begin
425
if (FPWID==128)
426
  redor128 u121 (.a(xdif11), .b({mfs,2'b0}), .o(sticky) );
427
else if (FPWID==96)
428
  redor96 u121 (.a(xdif11), .b({mfs,2'b0}), .o(sticky) );
429
else if (FPWID==84)
430
  redor84 u121 (.a(xdif11), .b({mfs,2'b0}), .o(sticky) );
431
else if (FPWID==80)
432
  redor80 u121 (.a(xdif11), .b({mfs,2'b0}), .o(sticky) );
433
else if (FPWID==64)
434
  redor64 u121 (.a(xdif11), .b({mfs,2'b0}), .o(sticky) );
435
else if (FPWID==32)
436
  redor32 u121 (.a(xdif11), .b({mfs,2'b0}), .o(sticky) );
437
else begin
438
        always @* begin
439
        $display("redor operation needed in fpFMA");
440
        $finish;
441
  end
442
end
443
end
444
endgenerate
445
*/
446
 
447
// register inputs to shifter and shift
448
always_comb
449
        sticky12 <= sticky;
450
always_comb
451
        xdif12 <= xdif11;
452
always_comb
453
        mfs12 <= mfs;
454
 
455
// -----------------------------------------------------------
456
// Clock #13
457
// - denormalize operand (shift right)
458
// -----------------------------------------------------------
459
reg [fp32Pkg::FX+2:0] mfs13;
460
reg [fp32Pkg::FX:0] mo13;
461
reg ex_gt_xc13;
462
reg [fp32Pkg::FMSB+1:0] fractc13;
463
reg ops13;
464
 
465
always_comb
466
        mo13 <= mo9;
467
always_comb
468
        ex_gt_xc13 <= ex_gt_xc9;
469
always_comb
470
        fractc13 <= fractc9;
471
always_comb
472
        ops13 <= ops10;
473
 
474
always_comb
475
        mfs13 <= ({mfs12,2'b0} >> xdif12)|sticky12;
476
 
477
// -----------------------------------------------------------
478
// Clock #14
479
// Sort operands
480
// -----------------------------------------------------------
481
reg [fp32Pkg::FX+2:0] oa, ob;
482
reg a_gt_b14;
483
 
484
always_comb
485
        a_gt_b14 <= a_gt_b8;
486
 
487
always_comb
488
         oa <= ops13 ? {mo13,2'b00} : mfs13;
489
always_comb
490
         ob <= ops13 ? mfs13 : {fractc13,{fp32Pkg::FMSB+1{1'b0}},2'b00};
491
 
492
// -----------------------------------------------------------
493
// Clock #15
494
// - Sort operands
495
// -----------------------------------------------------------
496
reg [fp32Pkg::FX+2:0] oaa, obb;
497
reg realOp15;
498
reg [fp32Pkg::EMSB:0] ex15;
499
reg underflow15;
500
 
501
//wire [fp32Pkg::EMSB:0] ex9c = ex9[fp32Pkg::EMSB+1] ? infXp : ex9[fp32Pkg::EMSB:0];
502
wire [fp32Pkg::EMSB:0] ex9c = (&ex9[fp32Pkg::EMSB:0] | ex9[fp32Pkg::EMSB+1]) & !ex9[fp32Pkg::EMSB+2] ? infXp : ex9[fp32Pkg::EMSB:0];
503
reg overflow15;
504
always_comb
505
        realOp15 <= realOp7;
506
always_comb
507
        ex15 <= ex9c;
508
always_comb
509
        overflow15 <= (ex9[fp32Pkg::EMSB+1]| &ex9[fp32Pkg::EMSB:0]) & !ex9[fp32Pkg::EMSB+2];
510
always_comb
511
        underflow15 = ex9[fp32Pkg::EMSB+2];
512
always_comb
513
         oaa <= a_gt_b14 ? oa : ob;
514
always_comb
515
         obb <= a_gt_b14 ? ob : oa;
516
 
517
// -----------------------------------------------------------
518
// Clock #16
519
// - perform add/subtract
520
// - addition can generate an extra bit, subtract can't go negative
521
// -----------------------------------------------------------
522
reg [fp32Pkg::FX+3:0] mab;
523
reg [fp32Pkg::FX:0] mo16;
524
reg [fp32Pkg::FMSB+1:0] fractc16;
525
reg Nan16;
526
reg cNan16;
527
reg aInf16, cInf16;
528
reg op16;
529
reg exinf16;
530
 
531
always_comb
532
        Nan16 <= qNaNOut5|aNan5|bNan5;
533
always_comb
534
        cNan16 <= cNan1;
535
always_comb
536
        aInf16 <= &ex6;
537
always_comb
538
        cInf16 <= cInf1;
539
always_comb
540
        op16 <= op1;
541
always_comb
542
        mo16 <= mo13;
543
always_comb
544
        fractc16 <= fractc9;
545
always_comb
546
        exinf16 <= &ex15;
547
 
548
always_comb
549
        mab <= realOp15 ? oaa - obb : oaa + obb;
550
 
551
// -----------------------------------------------------------
552
// Clock #17
553
// - adjust for Nans
554
// -----------------------------------------------------------
555
reg [fp32Pkg::EMSB:0] ex17;
556
reg [fp32Pkg::FX:0] mo17;
557
reg so17;
558
reg exinf17;
559
reg overflow17;
560
 
561
always_comb
562
        so17 <= so9;
563
always_comb
564
        ex17 <= ex15;
565
always_comb
566
        exinf17 <= exinf16;
567
always_comb
568
        overflow17 <= overflow15;
569
 
570
always_comb
571
        casez({aInf16&cInf16,Nan16,cNan16,exinf16})
572
        4'b1???:        mo17 <= {1'b0,op16,{fp32Pkg::FMSB-1{1'b0}},op16,{fp32Pkg::FMSB{1'b0}}}; // inf +/- inf - generate QNaN on subtract, inf on add
573
        4'b01??:        mo17 <= {1'b0,mo16};
574
        4'b001?:        mo17 <= {1'b1,1'b1,fractc16[fp32Pkg::FMSB-1:0],{fp32Pkg::FMSB+1{1'b0}}};
575
        4'b0001:        mo17 <= 1'd0;
576
        default:        mo17 <= mab[fp32Pkg::FX+3:2];           // mab has two extra lead bits and two trailing bits
577
        endcase
578
 
579
assign o.sign = so17;
580
assign o.exp = ex17;
581
assign o.sig = mo17;
582
 
583
assign zero = {ex17,mo17}==1'd0;
584
assign inf = exinf17;
585
assign under = underflow15;//ex17==1'd0;
586
assign over = overflow17;
587
 
588
endmodule
589
 
590
 
591
// Multiplier with normalization and rounding.
592
 
593
module fpFMA32nrCombo(op, rm, a, b, c, o, inf, zero, overflow, underflow, inexact);
594
input op;
595
input [2:0] rm;
596
input  FP32 a, b, c;
597
output FP32 o;
598
output zero;
599
output inf;
600
output reg overflow;
601
output reg underflow;
602
output reg inexact;
603
 
604
wire FP32X fma_o;
605
wire fma_underflow;
606
wire fma_overflow;
607
wire norm_underflow;
608
wire norm_inexact;
609
wire sign_exe1, inf1, overflow1, underflow1;
610
wire FP32N fpn0;
611
 
612
fpFMA32combo u1
613
(
614
        .op(op),
615
        .rm(rm),
616
        .a(a),
617
        .b(b),
618
        .c(c),
619
        .o(fma_o),
620
        .under(fma_underflow),
621
        .over(fma_overflow),
622
        .zero(),
623
        .inf()
624
);
625
fpNormalize32combo u2
626
(
627
        .i(fma_o),
628
        .o(fpn0),
629
        .under_i(fma_underflow),
630
        .under_o(norm_underflow),
631
        .inexact_o(norm_inexact)
632
);
633
fpRound32combo u3(.rm(rm), .i(fpn0), .o(o) );
634
fpDecomp32 u4(.i(o), .xz(), .vz(zero), .inf(inf));
635
always_comb
636
        underflow <= fma_underflow;
637
always_comb
638
        overflow <= fma_overflow;
639
always_comb
640
        inexact <= norm_inexact;
641
//assign overflow = inf;
642
 
643
endmodule
644
 

powered by: WebSVN 2.1.0

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