-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFloatWrapper.scala
26 lines (23 loc) · 928 Bytes
/
FloatWrapper.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package fpDivision
import chisel3._
import chisel3.util.Cat
// Wraps a Chisel Flo or Dbl datatype to allow easy
// extraction of the different parts (sign, exponent, mantissa)
class FloatWrapper(val num: Bits) {
val (sign, exponent, mantissa, zero) = num.getWidth match {
case 32 => (num(31).toBool(),
num(30, 23).toUInt,
// if the exponent is 0
// this is a denormalized number
Cat(Mux(num(30, 23) === Bits(0),
Bits(0, 1), Bits(1, 1)),
num(22, 0).toUInt),
num(30, 0) === Bits(0))
case 64 => (num(63).toBool(),
num(62, 52).toUInt,
Cat(Mux(num(62, 52) === Bits(0),
Bits(0, 1), Bits(1, 1)),
num(51, 0).toUInt),
num(62, 0) === Bits(0))
}
}