Line 56... |
Line 56... |
//
|
//
|
// ============================================================================
|
// ============================================================================
|
|
|
import fp::*;
|
import fp::*;
|
|
|
module DFPMultiply(clk, ce, a, b, o, sign_exe, inf, overflow, underflow);
|
//`define DFPMUL_PARALLEL 1'b1
|
|
|
|
module DFPMultiply(clk, ce, ld, a, b, o, sign_exe, inf, overflow, underflow, done);
|
input clk;
|
input clk;
|
input ce;
|
input ce;
|
|
input ld;
|
input [127:0] a, b;
|
input [127:0] a, b;
|
output [243:0] o;
|
output [243:0] o;
|
output sign_exe;
|
output sign_exe;
|
output inf;
|
output inf;
|
output overflow;
|
output overflow;
|
output underflow;
|
output underflow;
|
|
output done;
|
parameter DELAY =
|
parameter DELAY =
|
(FPWID == 128 ? 17 :
|
(FPWID == 128 ? 17 :
|
FPWID == 80 ? 17 :
|
FPWID == 80 ? 17 :
|
FPWID == 64 ? 13 :
|
FPWID == 64 ? 13 :
|
FPWID == 40 ? 8 :
|
FPWID == 40 ? 8 :
|
Line 111... |
Line 115... |
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
// First clock
|
// First clock
|
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
|
|
reg under, over;
|
reg under, over;
|
reg [15:0] sum_ex;
|
reg [15:0] sum_ex, sum_ex1;
|
reg sx0;
|
reg sx0;
|
|
wire done1;
|
|
|
DFPDecompose u1a (.i(a), .sgn(sa), .sx(sxa), .exp(xa), .sig(siga), .xz(a_dn), .vz(az), .inf(aInf), .nan(aNan) );
|
DFPDecompose u1a (.i(a), .sgn(sa), .sx(sxa), .exp(xa), .sig(siga), .xz(a_dn), .vz(az), .inf(aInf), .nan(aNan) );
|
DFPDecompose u1b (.i(b), .sgn(sb), .sx(sxb), .exp(xb), .sig(sigb), .xz(b_dn), .vz(bz), .inf(bInf), .nan(bNan) );
|
DFPDecompose u1b (.i(b), .sgn(sb), .sx(sxb), .exp(xb), .sig(sigb), .xz(b_dn), .vz(bz), .inf(bInf), .nan(bNan) );
|
|
|
// Compute the sum of the exponents.
|
// Compute the sum of the exponents.
|
Line 124... |
Line 129... |
wire [15:0] xapxb, xamxb, xbmxa;
|
wire [15:0] xapxb, xamxb, xbmxa;
|
wire xapxbc, xamxbc, xbmxac;
|
wire xapxbc, xamxbc, xbmxac;
|
BCDAddN #(.N(4)) u1c (.ci(1'b0), .a(xa), .b(xb), .o(xapxb), .co(xapxbc));
|
BCDAddN #(.N(4)) u1c (.ci(1'b0), .a(xa), .b(xb), .o(xapxb), .co(xapxbc));
|
BCDSubN #(.N(4)) u1d (.ci(1'b0), .a(xa), .b(xb), .o(xamxb), .co(xamxbc));
|
BCDSubN #(.N(4)) u1d (.ci(1'b0), .a(xa), .b(xb), .o(xamxb), .co(xamxbc));
|
BCDSubN #(.N(4)) u1e (.ci(1'b0), .a(xb), .b(xa), .o(xbmxa), .co(xbmxac));
|
BCDSubN #(.N(4)) u1e (.ci(1'b0), .a(xb), .b(xa), .o(xbmxa), .co(xbmxac));
|
|
BCDSubN #(.N(5)) u1h (.ci(1'b0), .a(20'h10000), .b(sum_ex1), .o(sum_ex2), .co());
|
|
|
always @*
|
always @*
|
case({sxa,sxb})
|
case({sxa,sxb})
|
2'b11: begin sum_ex <= xapxb; over <= xapxbc; under <= 1'b0; sx0 <= sxa; end
|
2'b11: begin sum_ex1 <= xapxb; over <= xapxbc; under <= 1'b0; sx0 <= sxa; end
|
2'b01: begin sum_ex <= xbmxa; over <= 1'b0; under <= 1'b0; sx0 <= ~xbmxac; end
|
2'b01: begin sum_ex1 <= xbmxa; over <= 1'b0; under <= 1'b0; sx0 <= ~xbmxac; end
|
2'b10: begin sum_ex <= xamxb; over <= 1'b0; under <= 1'b0; sx0 <= ~xamxbc; end
|
2'b10: begin sum_ex1 <= xamxb; over <= 1'b0; under <= 1'b0; sx0 <= ~xamxbc; end
|
2'b00: begin sum_ex <= xapxb; over <= 1'b0; under <= xapxbc; sx0 <= sxa; end
|
2'b00: begin sum_ex1 <= xapxb; over <= 1'b0; under <= xapxbc; sx0 <= sxa; end
|
endcase
|
endcase
|
|
|
|
// Take nine's complement if exponent sign changed.
|
|
always @*
|
|
if ((sxa^sxb)) begin
|
|
if ((sxa & xamxbc) || (sxb & xbmxac))
|
|
sum_ex <= sum_ex2;
|
|
else
|
|
sum_ex <= sum_ex1;
|
|
end
|
|
else
|
|
sum_ex <= sum_ex1;
|
|
|
wire [255:0] sigoo;
|
wire [255:0] sigoo;
|
|
`ifdef DFPMUL_PARALLEL
|
BCDMul32 u1f (.a({20'h0,siga}),.b({20'h0,sigb}),.o(sigoo));
|
BCDMul32 u1f (.a({20'h0,siga}),.b({20'h0,sigb}),.o(sigoo));
|
|
`else
|
|
dfmul u1g
|
|
(
|
|
.clk(clk),
|
|
.ld(ld),
|
|
.a(siga),
|
|
.b(sigb),
|
|
.p(sigoo),
|
|
.done(done1)
|
|
);
|
|
`endif
|
|
|
always @(posedge clk)
|
always @(posedge clk)
|
if (ce) sig1 <= sigoo[215:0];
|
if (ce) sig1 <= sigoo[215:0];
|
|
|
// Status
|
// Status
|
Line 164... |
Line 193... |
// - correct xponent and mantissa for exceptional conditions
|
// - correct xponent and mantissa for exceptional conditions
|
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
|
|
wire so1, sx1;
|
wire so1, sx1;
|
reg [3:0] st;
|
reg [3:0] st;
|
|
wire done1a;
|
|
|
delay #(.WID(1),.DEP(1)) u8 (.clk(clk), .ce(ce), .i(~(sa ^ sb)), .o(so1) );// two clock delay!
|
delay #(.WID(1),.DEP(1)) u8 (.clk(clk), .ce(ce), .i(~(sa ^ sb)), .o(so1) );// two clock delay!
|
delay #(.WID(1),.DEP(1)) u9 (.clk(clk), .ce(ce), .i(sx0), .o(sx1) );// two clock delay!
|
delay #(.WID(1),.DEP(1)) u9 (.clk(clk), .ce(ce), .i(sx0), .o(sx1) );// two clock delay!
|
|
|
always @(posedge clk)
|
always @(posedge clk)
|
Line 204... |
Line 234... |
|
|
delay #(.WID(1),.DEP(DELAY+1)) u10 (.clk(clk), .ce(ce), .i(sa & sb), .o(sign_exe) );
|
delay #(.WID(1),.DEP(DELAY+1)) u10 (.clk(clk), .ce(ce), .i(sa & sb), .o(sign_exe) );
|
delay1 u11 (.clk(clk), .ce(ce), .i(over1), .o(overflow) );
|
delay1 u11 (.clk(clk), .ce(ce), .i(over1), .o(overflow) );
|
delay1 u12 (.clk(clk), .ce(ce), .i(over1), .o(inf) );
|
delay1 u12 (.clk(clk), .ce(ce), .i(over1), .o(inf) );
|
delay1 u13 (.clk(clk), .ce(ce), .i(under1), .o(underflow) );
|
delay1 u13 (.clk(clk), .ce(ce), .i(under1), .o(underflow) );
|
|
delay #(.WID(1),.DEP(3)) u18 (.clk(clk), .ce(ce), .i(done1), .o(done1a) );
|
|
|
assign o = {st,xo1,mo1,8'h00};
|
assign o = {st,xo1,mo1,8'h00};
|
|
assign done = done1&done1a;
|
|
|
endmodule
|
endmodule
|
|
|
|
|
// Multiplier with normalization and rounding.
|
// Multiplier with normalization and rounding.
|
|
|
module DFPMultiplynr(clk, ce, a, b, o, rm, sign_exe, inf, overflow, underflow);
|
module DFPMultiplynr(clk, ce, ld, a, b, o, rm, sign_exe, inf, overflow, underflow, done);
|
input clk;
|
input clk;
|
input ce;
|
input ce;
|
|
input ld;
|
input [127:0] a, b;
|
input [127:0] a, b;
|
output [127:0] o;
|
output [127:0] o;
|
input [2:0] rm;
|
input [2:0] rm;
|
output sign_exe;
|
output sign_exe;
|
output inf;
|
output inf;
|
output overflow;
|
output overflow;
|
output underflow;
|
output underflow;
|
|
output done;
|
|
|
|
wire done1, done1a;
|
wire [243:0] o1;
|
wire [243:0] o1;
|
wire sign_exe1, inf1, overflow1, underflow1;
|
wire sign_exe1, inf1, overflow1, underflow1;
|
wire [131:0] fpn0;
|
wire [131:0] fpn0;
|
|
|
DFPMultiply u1 (clk, ce, a, b, o1, sign_exe1, inf1, overflow1, underflow1);
|
DFPMultiply u1 (clk, ce, ld, a, b, o1, sign_exe1, inf1, overflow1, underflow1, done1);
|
DFPNormalize u2(.clk(clk), .ce(ce), .under_i(underflow1), .i(o1), .o(fpn0) );
|
DFPNormalize u2(.clk(clk), .ce(ce), .under_i(underflow1), .i(o1), .o(fpn0) );
|
DFPRound u3(.clk(clk), .ce(ce), .rm(rm), .i(fpn0), .o(o) );
|
DFPRound u3(.clk(clk), .ce(ce), .rm(rm), .i(fpn0), .o(o) );
|
delay2 #(1) u4(.clk(clk), .ce(ce), .i(sign_exe1), .o(sign_exe));
|
delay2 #(1) u4(.clk(clk), .ce(ce), .i(sign_exe1), .o(sign_exe));
|
delay2 #(1) u5(.clk(clk), .ce(ce), .i(inf1), .o(inf));
|
delay2 #(1) u5(.clk(clk), .ce(ce), .i(inf1), .o(inf));
|
delay2 #(1) u6(.clk(clk), .ce(ce), .i(overflow1), .o(overflow));
|
delay2 #(1) u6(.clk(clk), .ce(ce), .i(overflow1), .o(overflow));
|
delay2 #(1) u7(.clk(clk), .ce(ce), .i(underflow1), .o(underflow));
|
delay2 #(1) u7(.clk(clk), .ce(ce), .i(underflow1), .o(underflow));
|
|
delay #(.WID(1),.DEP(11)) u10 (.clk(clk), .ce(ce), .i(done1), .o(done1a) );
|
|
assign done = done1 & done1a;
|
|
|
endmodule
|
endmodule
|