Skip to content

Commit 3fbd243

Browse files
committed
fix subndom handling for narrow acc/prod prcisions
1 parent f38f913 commit 3fbd243

1 file changed

Lines changed: 4 additions & 22 deletions

File tree

src/main/scala/gemmini/MxFPMul.scala

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -352,39 +352,21 @@ object MxPEOutToRaw {
352352
val expIn = exp(expWidth, 0)
353353
val fractIn = sig(sigWidth-2, 0)
354354

355-
val isZeroExpIn = (expIn === 0.U)
356-
val isZeroFractIn = (fractIn === 0.U)
357-
358-
val normDist = countLeadingZeros(fractIn)
359-
val subnormFract = if (sigWidth > 2) {
360-
(fractIn << normDist) (sigWidth - 3, 0) << 1
361-
} else {
362-
0.U
363-
}
364-
val adjustedExp =
365-
Mux(isZeroExpIn,
366-
normDist ^ ((BigInt(1) << (expWidth + 1)) - 1).U,
367-
expIn
368-
) + ((BigInt(1) << (expWidth - 1)).U
369-
| Mux(isZeroExpIn, 2.U, 1.U))
370-
371-
val isZero = isZeroExpIn && isZeroFractIn
355+
val adjustedExp = expIn + ((BigInt(1) << (expWidth - 1)).U | 1.U)
372356
val isSpecial = adjustedExp(expWidth, expWidth - 1) === 3.U
373357

374-
// Saturate to max finite value (FP8 E4M3 alt0: 0x7E = 448) on exponent overflow
375-
// but propagate NaN when an input was actually NaN
376358
val satExp = (BigInt(3) << (expWidth - 1)).U((expWidth + 1).W)
377359
val satFrac = ((BigInt(1) << (sigWidth - 1)) - 2).U((sigWidth - 1).W)
378-
val saturate = isSpecial && !inputNaN
379-
val effectiveZero = (isZero || inputZero) && !inputNaN
360+
val saturate = isSpecial && !inputNaN
361+
val effectiveZero = (inputZero) && !inputNaN
380362

381363
val out = Wire(new RawFloat(expWidth, sigWidth))
382364
out.isNaN := inputNaN
383365
out.isInf := false.B
384366
out.isZero := effectiveZero
385367
out.sign := sign
386368
out.sExp := Mux(inputNaN || saturate, satExp, adjustedExp(expWidth, 0)).zext
387-
out.sig := 0.U(1.W) ## !effectiveZero ## Mux(inputNaN || saturate, satFrac, Mux(isZeroExpIn, subnormFract, fractIn))
369+
out.sig := 0.U(1.W) ## !effectiveZero ## Mux(inputNaN || saturate, satFrac, fractIn)
388370
out
389371
}
390372
}

0 commit comments

Comments
 (0)