@@ -40,30 +40,7 @@ class MxFpMul (lut: Boolean) (fpProductPrecision: (Int, Int), fpAccPrecision: Mx
4040 val leftShift = Mux (isPositiveShift, 0 .U , PriorityEncoder (prod.asBools.reverse))
4141 val expAdj = Mux (isPositiveShift, 1 .U , leftShift -& 1 .U )
4242 val aligned = prod << leftShift
43-
44- // After alignment, the hidden-1 sits at bit inBits-1.
45- // The outBits fraction bits we want occupy [inBits-2 : inBits-1-outBits].
46- // Everything below that window is discarded; we must round instead of truncate.
47- val truncated = aligned(inBits - 2 , inBits - 1 - outBits)
48-
49- // bitsBelow: how many bits fall below the fraction window (elaboration-time constant)
50- val bitsBelow = inBits - 1 - outBits
51- // roundBit: MSB of the discarded portion (the deciding rounding bit)
52- val roundBit : Bool = if (bitsBelow >= 1 ) aligned(inBits - 2 - outBits) else false .B
53- // stickyBit: OR of all bits below the round bit; non-zero means we are strictly > midpoint
54- val stickyBit : Bool = if (bitsBelow >= 2 ) aligned(inBits - 3 - outBits, 0 ).orR else false .B
55- // Round-to-nearest-even: increment when roundBit=1 AND (past midpoint OR at midpoint with odd LSB)
56- val doRound = roundBit && (stickyBit || truncated(0 ))
57-
58- // +& is width-growing addition: result is (outBits+1) bits, capturing any carry-out
59- val rounded = truncated +& doRound
60- // roundOverflow: set when all outBits fraction bits were 1 and the increment wraps to 0
61- // In that case the normalised significand becomes 1.000…0 and the exponent gains +1
62- val roundOverflow = rounded(outBits)
63- val finalSig = Mux (roundOverflow, 0 .U (outBits.W ), rounded(outBits - 1 , 0 ))
64- val finalExpAdj = expAdj +& roundOverflow
65-
66- (Mux (isZero, 0 .U (outBits.W ), finalSig), Mux (isZero, 0 .U , finalExpAdj), isPositiveShift)
43+ (Mux (isZero, 0 .U (outBits.W ), aligned(inBits - 2 , inBits - 1 - outBits)), Mux (isZero, 0 .U , expAdj), isPositiveShift)
6744 } else {
6845 val isZero = prod === 0 .U
6946 val extraPad = outBits - inBits
@@ -74,8 +51,8 @@ class MxFpMul (lut: Boolean) (fpProductPrecision: (Int, Int), fpAccPrecision: Mx
7451 val aligned = realProd << leftShift
7552 ((Mux (isZero, 0 .U (outBits.W ), aligned(inBits- 1 , 0 ) << (extraPad))(outBits- 1 , 0 )), Mux (isZero, 0 .U , expAdj), isPositiveShift)
7653
77- }
7854 }
55+ }
7956
8057 def pack (c : MxClassifiedFp , w_exp : Int , w_sig : Int , padExp : Int ): (UInt , UInt , UInt ) = {
8158 val packed_sig = Mux (c.isZero, 0 .U , (~ c.isSub.asUInt ## c.sig))
0 commit comments