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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [DFPMultiply96.sv] - Blame information for rev 75

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 75 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//        __
4
//   \\__/ o\    (C) 2020-2022  Robert Finch, Waterloo
5
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch@finitron.ca
7
//       ||
8
//
9
//      DFPMultiply96.v
10
//              - decimal floating point multiplier
11
//              - parameterized width
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
//      Floating Point Multiplier
42
//
43
//      Properties:
44
//      +-inf * +-inf = -+inf   (this is handled by exOver)
45
//      +-inf * 0     = QNaN
46
//
47
// ============================================================================
48
 
49
import DFPPkg::*;
50
 
51
//`define DFPMUL_PARALLEL       1'b1
52
 
53
module DFPMultiply96(clk, ce, ld, a, b, o, sign_exe, inf, overflow, underflow, done);
54
localparam N=25;
55
localparam DELAY = 2;
56
input clk;
57
input ce;
58
input ld;
59
input  DFP96 a, b;
60
output DFP96UD o;
61
output sign_exe;
62
output inf;
63
output overflow;
64
output underflow;
65
output done;
66
 
67
reg [11:0] xo1;         // extra bit for sign
68
reg [N*4*2-1:0] mo1;
69
 
70
// constants
71
wire [11:0] infXp = 12'hBFF;    // infinite / NaN - all ones
72
wire [11:0] bias = 12'h5FF;
73
// The following is the value for an exponent of zero, with the offset
74
// eg. 8'h7f for eight bit exponent, 11'h7ff for eleven bit exponent, etc.
75
// The following is a template for a quiet nan. (MSB=1)
76
wire [N*4-1:0] qNaN  = {4'h1,{96{1'b0}}};
77
 
78
// variables
79
reg [N*4*2-1:0] sig1;
80
wire [13:0] ex2;
81
 
82
DFP96U au, bu;
83
DFPUnpack96 u01 (a, au);
84
DFPUnpack96 u02 (b, bu);
85
 
86
// Decompose the operands
87
wire sa, sb;                    // sign bit
88
wire [14:0] xa, xb;     // exponent bits
89
wire sxa, sxb;
90
wire [N*4-1:0] siga, sigb;
91
wire a_dn, b_dn;                        // a/b is denormalized
92
wire aNan1, bNan1;
93
wire az, bz;
94
wire aInf1, bInf1;
95
 
96
assign siga = au.sig;
97
assign sigb = bu.sig;
98
assign az = au.exp==12'h0 && au.sig==100'd0;
99
assign bz = bu.exp==12'h0 && bu.sig==100'd0;
100
 
101
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
102
// Clock #1
103
// - decode the input operands
104
// - derive basic information
105
// - calculate exponent
106
// - calculate fraction
107
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
108
 
109
// -----------------------------------------------------------
110
// First clock
111
// Compute the sum of the exponents.
112
// -----------------------------------------------------------
113
 
114
wire under, over;
115
wire [13:0] sum_ex = au.exp + bu.exp - bias;
116
reg sx0;
117
wire done1;
118
assign under = &sum_ex[13:12];
119
assign over = sum_ex > 14'hBFF && !under;
120
 
121
wire [N*4*2-1:0] sigoo;
122
`ifdef DFPMUL_PARALLEL
123
BCDMul32 u1f (.a({20'h0,siga}),.b({20'h0,sigb}),.o(sigoo));
124
`else
125
dfmul #(.N(N)) u1g
126
(
127
        .clk(clk),
128
        .ld(ld),
129
        .a(siga),
130
        .b(sigb),
131
        .p(sigoo),
132
        .done(done1)
133
);
134
`endif
135
 
136
always_ff @(posedge clk)
137
  if (ce) sig1 <= sigoo[N*4*2-1:0];
138
 
139
// Status
140
wire under1, over1;
141
 
142
ft_delay #(.WID(12),.DEP(DELAY)) u3 (.clk(clk), .ce(ce), .i(sum_ex[11:0]), .o(ex2) );
143
ft_delay #(.WID(1),.DEP(DELAY)) u2a (.clk(clk), .ce(ce), .i(au.infinity), .o(aInf1) );
144
ft_delay #(.WID(1),.DEP(DELAY)) u2b (.clk(clk), .ce(ce), .i(bu.infinity), .o(bInf1) );
145
ft_delay #(.WID(1),.DEP(DELAY)) u6  (.clk(clk), .ce(ce), .i(under), .o(under1) );
146
ft_delay #(.WID(1),.DEP(DELAY)) u7  (.clk(clk), .ce(ce), .i(over), .o(over1) );
147
 
148
// determine when a NaN is output
149
wire qNaNOut;
150
wire DFP96U a1,b1;
151
wire asnan, bsnan, aqnan, bqnan;
152
ft_delay #(.WID(1),.DEP(DELAY)) u5 (.clk(clk), .ce(ce), .i((au.infinity&bz)|(bu.infinity&az)), .o(qNaNOut) );
153
ft_delay #(.WID(1),.DEP(DELAY)) u14 (.clk(clk), .ce(ce), .i(au.nan), .o(aNan1) );
154
ft_delay #(.WID(1),.DEP(DELAY)) u15 (.clk(clk), .ce(ce), .i(bu.nan), .o(bNan1) );
155
ft_delay #(.WID(1),.DEP(DELAY)) u18 (.clk(clk), .ce(ce), .i(au.snan), .o(asnan) );
156
ft_delay #(.WID(1),.DEP(DELAY)) u19 (.clk(clk), .ce(ce), .i(bu.snan), .o(bsnan) );
157
ft_delay #(.WID(1),.DEP(DELAY)) u18a (.clk(clk), .ce(ce), .i(au.qnan), .o(aqnan) );
158
ft_delay #(.WID(1),.DEP(DELAY)) u19a (.clk(clk), .ce(ce), .i(bu.qnan), .o(bqnan) );
159
ft_delay #(.WID($bits(a1)),.DEP(DELAY))  u16 (.clk(clk), .ce(ce), .i(a), .o(a1) );
160
ft_delay #(.WID($bits(b1)),.DEP(DELAY))  u17 (.clk(clk), .ce(ce), .i(b), .o(b1) );
161
 
162
// -----------------------------------------------------------
163
// Second clock
164
// - correct xponent and mantissa for exceptional conditions
165
// -----------------------------------------------------------
166
 
167
wire so1, sx1;
168
reg [3:0] st;
169
wire done1a;
170
 
171
ft_delay #(.WID(1),.DEP(1)) u8 (.clk(clk), .ce(ce), .i(au.sign ^ bu.sign), .o(so1) );// two clock delay!
172
 
173
always_ff @(posedge clk)
174
        if (ce)
175
                casez({qNaNOut|aNan1|bNan1,aInf1,bInf1,over1,under1})
176
                5'b1????:       xo1 = infXp;    // qNaN - infinity * zero
177
                5'b01???:       xo1 = infXp;    // 'a' infinite
178
                5'b001??:       xo1 = infXp;    // 'b' infinite
179
                5'b0001?:       xo1 = infXp;    // result overflow
180
                5'b00001:       xo1 = ex2[11:0];//0;            // underflow
181
                default:        xo1 = ex2[11:0];        // situation normal
182
                endcase
183
 
184
// Force mantissa to zero when underflow or zero exponent when not supporting denormals.
185
always_ff @(posedge clk)
186
        if (ce)
187
                casez({aNan1,bNan1,qNaNOut,aInf1,bInf1,over1|under1})
188
                6'b1?????:  mo1 = {4'h1,a1[N*4-4-1:0],{N*4{1'b0}}};
189
    6'b01????:  mo1 = {4'h1,b1[N*4-4-1:0],{N*4{1'b0}}};
190
                6'b001???:      mo1 = {4'h1,qNaN|3'd4,{N*4{1'b0}}};     // multiply inf * zero
191
                6'b0001??:      mo1 = 0;        // mul inf's
192
                6'b00001?:      mo1 = 0;        // mul inf's
193
                6'b000001:      mo1 = 0;        // mul overflow
194
                default:        mo1 = sig1;
195
                endcase
196
 
197
ft_delay #(.WID(1),.DEP(DELAY+1)) u10 (.clk(clk), .ce(ce), .i(sa & sb), .o(sign_exe) );
198
delay1 u11 (.clk(clk), .ce(ce), .i(over1),  .o(overflow) );
199
delay1 u12 (.clk(clk), .ce(ce), .i(over1),  .o(inf) );
200
delay1 u13 (.clk(clk), .ce(ce), .i(under1), .o(underflow) );
201
ft_delay #(.WID(1),.DEP(3)) u18b (.clk(clk), .ce(ce), .i(done1), .o(done1a) );
202
 
203
assign o.nan = aNan1|bNan1|qNaNOut;
204
assign o.qnan = qNaNOut|aqnan|bqnan;
205
assign o.snan = qNaNOut ? 1'b0 : asnan|bsnan;
206
assign o.infinity = aInf1|bInf1|over;
207
assign o.sign = so1;
208
assign o.exp = xo1;
209
assign o.sig = {mo1,8'h00};
210
assign done = done1&done1a;
211
 
212
endmodule
213
 
214
 
215
// Multiplier with normalization and rounding.
216
 
217
module DFPMultiply96nr(clk, ce, ld, a, b, o, rm, sign_exe, inf, overflow, underflow, done);
218
localparam N=25;
219
input clk;
220
input ce;
221
input ld;
222
input  DFP96 a, b;
223
output DFP96 o;
224
input [2:0] rm;
225
output sign_exe;
226
output inf;
227
output overflow;
228
output underflow;
229
output done;
230
 
231
wire done1, done1a;
232
DFP96UD o1;
233
wire sign_exe1, inf1, overflow1, underflow1;
234
DFP96UN fpn0;
235
 
236
DFPMultiply96  u1 (clk, ce, ld, a, b, o1, sign_exe1, inf1, overflow1, underflow1, done1);
237
DFPNormalize96 u2(.clk(clk), .ce(ce), .under_i(underflow1), .i(o1), .o(fpn0) );
238
DFPRound96     u3(.clk(clk), .ce(ce), .rm(rm), .i(fpn0), .o(o) );
239
delay2      #(1)   u4(.clk(clk), .ce(ce), .i(sign_exe1), .o(sign_exe));
240
delay2      #(1)   u5(.clk(clk), .ce(ce), .i(inf1), .o(inf));
241
delay2      #(1)   u6(.clk(clk), .ce(ce), .i(overflow1), .o(overflow));
242
delay2      #(1)   u7(.clk(clk), .ce(ce), .i(underflow1), .o(underflow));
243
ft_delay #(.WID(1),.DEP(12)) u10 (.clk(clk), .ce(ce), .i(done1), .o(done1a) );
244
assign done = done1 & done1a;
245
 
246
endmodule

powered by: WebSVN 2.1.0

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