@@ -31,7 +31,7 @@ class PositFMA(val totalBits: Int, val es: Int) extends Module with HasHardPosit
31
31
val productSign = num1.sign ^ num2.sign ^ io.negate
32
32
val addendSign = num3.sign ^ io.negate ^ io.sub
33
33
34
- val productExponent = num1.exponent + num2.exponent
34
+ val productExponent = num1.exponent +& num2.exponent
35
35
val productFraction =
36
36
WireInit (UInt (maxMultiplierFractionBits.W ), num1.fraction * num2.fraction)
37
37
@@ -40,13 +40,14 @@ class PositFMA(val totalBits: Int, val es: Int) extends Module with HasHardPosit
40
40
val normProductExponent = productExponent + Mux (prodOverflow, 1 .S , 0 .S )
41
41
val prodStickyBit = Mux (prodOverflow, productFraction(0 ), false .B )
42
42
43
- val addendFraction = (num3.fraction << maxFractionBits).asUInt
43
+ val addendIsZero = num3.isZero
44
+ val addendFraction = Mux (! addendIsZero, (num3.fraction << maxFractionBits).asUInt, 0 .U )
44
45
val addendExponent = num3.exponent
45
46
46
47
val isAddendLargerThanProduct =
47
- (addendExponent > normProductExponent) |
48
- (addendExponent === normProductExponent &&
49
- (addendFraction > normProductFraction))
48
+ ~ addendIsZero &
49
+ (( addendExponent > normProductExponent) |
50
+ (addendExponent === normProductExponent && ( addendFraction > normProductFraction) ))
50
51
51
52
val largeExp = Mux (isAddendLargerThanProduct, addendExponent, normProductExponent)
52
53
val largeFrac = Mux (isAddendLargerThanProduct, addendFraction, normProductFraction)
@@ -57,28 +58,29 @@ class PositFMA(val totalBits: Int, val es: Int) extends Module with HasHardPosit
57
58
val smallSign = Mux (isAddendLargerThanProduct, productSign, addendSign)
58
59
59
60
val expDiff = (largeExp - smallExp).asUInt()
61
+ val ShftInBound = expDiff < maxMultiplierFractionBits.U
60
62
val shiftedSmallFrac =
61
63
Mux (expDiff < maxMultiplierFractionBits.U , smallFrac >> expDiff, 0 .U )
62
64
val smallFracStickyBit = (smallFrac & ((1 .U << expDiff) - 1 .U )).orR()
63
65
64
66
val isAddition = ~ (largeSign ^ smallSign)
65
- val signedSmallerFraction =
67
+ val signedSmallerFrac =
66
68
Mux (isAddition, shiftedSmallFrac, ~ shiftedSmallFrac + 1 .U )
67
69
val fmaFraction =
68
- WireInit (UInt (maxMultiplierFractionBits.W ), largeFrac +& signedSmallerFraction )
70
+ WireInit (UInt (maxMultiplierFractionBits.W ), largeFrac +& signedSmallerFrac )
69
71
70
- val sumOverflow = fmaFraction(maxMultiplierFractionBits - 1 )
72
+ val fmaOverflow = isAddition & fmaFraction(maxMultiplierFractionBits - 1 )
71
73
val adjFmaFraction =
72
- Mux (isAddition , fmaFraction >> sumOverflow.asUInt( ), fmaFraction(maxMultiplierFractionBits - 2 , 0 ))
73
- val adjFmaExponent = largeExp + Mux (isAddition & sumOverflow , 1 .S , 0 .S )
74
- val sumStickyBit = Mux (isAddition & sumOverflow , fmaFraction(0 ), false .B )
74
+ Mux (fmaOverflow , fmaFraction(maxMultiplierFractionBits - 1 , 1 ), fmaFraction(maxMultiplierFractionBits - 2 , 0 ))
75
+ val adjFmaExponent = largeExp + Mux (fmaOverflow , 1 .S , 0 .S )
76
+ val sumStickyBit = Mux (fmaOverflow , fmaFraction(0 ), false .B )
75
77
76
78
val normalizationFactor = MuxCase (0 .S , Array .range(0 , maxMultiplierFractionBits - 2 ).map(index => {
77
79
(adjFmaFraction(maxMultiplierFractionBits - 2 , maxMultiplierFractionBits - index - 2 ) === 1 .U ) -> index.S
78
80
}))
79
81
80
82
val normFmaExponent = adjFmaExponent - normalizationFactor
81
- val normFmaFraction = adjFmaFraction << normalizationFactor.asUInt()
83
+ val normFmaFraction = ( adjFmaFraction << normalizationFactor.asUInt())(maxMultiplierFractionBits - 1 , 0 )
82
84
83
85
val result = Wire (new unpackedPosit(totalBits, es))
84
86
result.isNaR := num1.isNaR || num2.isNaR || num3.isNaR
0 commit comments