Skip to content

Commit

Permalink
Add a helper method to unpack IEEE floats
Browse files Browse the repository at this point in the history
  • Loading branch information
aswaterman committed Aug 30, 2019
1 parent 7c5e762 commit 186c14e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main/scala/tile/FPU.scala
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ case class FType(exp: Int, sig: Int) {
def ieeeWidth = exp + sig
def recodedWidth = ieeeWidth + 1

def qNaN = UInt((BigInt(7) << (exp + sig - 3)) + (BigInt(1) << (sig - 2)), exp + sig + 1)
def ieeeQNaN = UInt((BigInt(1) << (ieeeWidth - 1)) - (BigInt(1) << (sig - 2)), ieeeWidth)
def qNaN = UInt((BigInt(7) << (exp + sig - 3)) + (BigInt(1) << (sig - 2)), recodedWidth)
def isNaN(x: UInt) = x(sig + exp - 1, sig + exp - 3).andR
def isSNaN(x: UInt) = isNaN(x) && !x(sig - 2)

Expand Down Expand Up @@ -231,6 +232,19 @@ case class FType(exp: Int, sig: Int) {
Cat(sign, expOut, fractOut)
}

private def ieeeBundle = {
val expWidth = exp
class IEEEBundle extends Bundle {
val sign = Bool()
val exp = UInt(expWidth.W)
val sig = UInt((ieeeWidth-expWidth-1).W)
override def cloneType = new IEEEBundle().asInstanceOf[this.type]
}
new IEEEBundle
}

def unpackIEEE(x: UInt) = x.asTypeOf(ieeeBundle)

def recode(x: UInt) = hardfloat.recFNFromFN(exp, sig, x)
def ieee(x: UInt) = hardfloat.fNFromRecFN(exp, sig, x)
}
Expand Down

0 comments on commit 186c14e

Please sign in to comment.