cvw/wally-pipelined/src/fpu/fma2.sv

140 lines
4.5 KiB
Systemverilog
Raw Normal View History

2021-04-15 18:28:00 +00:00
////////////////////////////////////////////////////////////////////////////////
// Block Name: fmac.v
// Author: David Harris
// Date: 11/2/1995
//
// Block Description:
// This is the top level block of a floating-point multiply/accumulate
// unit(FMAC). It instantiates the following sub-blocks:
//
// array Booth encoding, partial product generation, product summation
// expgen Mxponent summation, compare, and adjust
// align Alignment shifter
// add Carry-save adder for accumulate, carry propagate adder
// lza Leading zero anticipator to control normalization shifter
// normalize Normalization shifter
// round Rounding of result
// exception Handles exceptional cases
2021-05-26 00:04:34 +00:00
// bypass Handles bypass of result to FInput1M or FInput3M input logics
2021-04-15 18:28:00 +00:00
// sign One bit sign handling block
2021-05-01 02:18:01 +00:00
// special Catch special cases (input logics = 0 / infinity / etc.)
2021-04-15 18:28:00 +00:00
//
2021-05-26 00:04:34 +00:00
// The FMAC computes FmaResultM=FInput1M*FInput2M+FInput3M, rounded with the mode specified by
2021-04-15 18:28:00 +00:00
// RN, RZ, RM, or RP. The result is optionally bypassed back to
2021-05-26 00:04:34 +00:00
// the FInput1M or FInput3M input logics for use on the next cycle. In addition, four signals
2021-04-15 18:28:00 +00:00
// are produced: trap, overflow, underflow, and inexact. Trap indicates
// an infinity, NaN, or denormalized number to be handled in software;
// the other three signals are IMMM flags.
//
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
2021-05-26 00:04:34 +00:00
module fma2(FInput1M, FInput2M, FInput3M, FrmM,
2021-04-15 18:28:00 +00:00
FmaResultM, FmaFlagsM, aligncntM, rM, sM,
tM, normcntM, aeM, bsM,killprodM,
xzeroM, yzeroM,zzeroM,xdenormM,ydenormM,
zdenormM,xinfM,yinfM,zinfM,xnanM,ynanM,znanM,
nanM,sumshiftM,sumshiftzeroM,prodinfM
);
/////////////////////////////////////////////////////////////////////////////
2021-05-01 02:18:01 +00:00
2021-05-26 00:04:34 +00:00
input logic [63:0] FInput1M; // input logic 1
input logic [63:0] FInput2M; // input logic 2
input logic [63:0] FInput3M; // input logic 3
2021-05-01 02:18:01 +00:00
input logic [2:0] FrmM; // Rounding mode
input logic [12:0] aligncntM; // status flags
input logic [105:0] rM; // one result of partial product sum
input logic [105:0] sM; // other result of partial products
input logic [163:0] tM; // output of alignment shifter
input logic [8:0] normcntM; // shift count for normalizer
input logic [12:0] aeM; // multiplier expoent
input logic bsM; // sticky bit of addend
2021-05-26 00:04:34 +00:00
input logic killprodM; // FInput3M >> product
2021-04-19 00:39:16 +00:00
input logic prodinfM;
input logic xzeroM;
input logic yzeroM;
input logic zzeroM;
input logic xdenormM;
input logic ydenormM;
input logic zdenormM;
input logic xinfM;
input logic yinfM;
input logic zinfM;
input logic xnanM;
input logic ynanM;
input logic znanM;
input logic nanM;
2021-05-01 02:18:01 +00:00
input logic [8:0] sumshiftM;
2021-04-19 00:39:16 +00:00
input logic sumshiftzeroM;
2021-05-01 02:18:01 +00:00
2021-05-26 00:04:34 +00:00
output logic [63:0] FmaResultM; // output FmaResultM=FInput1M*FInput2M+FInput3M
2021-05-01 02:18:01 +00:00
output logic [4:0] FmaFlagsM; // status flags
2021-04-15 18:28:00 +00:00
// Internal nodes
logic [163:0] sum; // output of carry prop adder
logic [53:0] v; // normalized sum, R, S bits
// logic [12:0] aligncnt; // shift count for alignment
logic [8:0] normcnt; // shift count for normalizer
logic negsum; // negate sum
logic invz; // invert addend
logic selsum1; // select +1 mode of sum
logic negsum0; // sum +0 < 0
logic negsum1; // sum +1 < 0
logic sumzero; // sum = 0
logic infinity; // generate infinity on overflow
logic sumof; // result out of range
logic zexpsel;
logic denorm0;
logic resultdenorm;
logic inf;
logic specialsel;
logic expplus1;
logic sumuf;
logic psign;
logic sticky;
logic [12:0] de0;
logic isAdd;
2021-05-03 19:17:09 +00:00
logic wsign;
logic [51:0] wman;
logic [10:0] wexp;
2021-04-15 18:28:00 +00:00
assign isAdd = 1;
// Instantiate fraction datapath
add add(.*);
lza lza(.*);
2021-05-26 00:04:34 +00:00
normalize normalize(.zexp(FInput3M[62:52]),.*);
round round(.xman(FInput1M[51:0]), .yman(FInput2M[51:0]),.zman(FInput3M[51:0]),.*);
2021-04-15 18:28:00 +00:00
// Instantiate exponent datapath
2021-05-26 00:04:34 +00:00
expgen2 expgen2(.xexp(FInput1M[62:52]),.yexp(FInput2M[62:52]),.zexp(FInput3M[62:52]),.*);
2021-04-15 18:28:00 +00:00
// Instantiate control logic
2021-05-26 00:04:34 +00:00
sign sign(.xsign(FInput1M[63]),.ysign(FInput2M[63]),.zsign(FInput3M[63]),.*);
flag2 flag2(.xsign(FInput1M[63]),.ysign(FInput2M[63]),.zsign(FInput3M[63]),.vbits(v[1:0]),.*);
2021-04-15 18:28:00 +00:00
2021-05-03 19:17:09 +00:00
assign FmaResultM = {wsign,wexp,wman};
2021-04-15 18:28:00 +00:00
endmodule