summaryrefslogtreecommitdiff
path: root/src/main/scala/chisel3/util/BitPat.scala
diff options
context:
space:
mode:
authorDonggyu2016-07-11 15:17:59 -0700
committerAndrew Waterman2016-07-11 15:17:59 -0700
commitbb5467fc67d3b8fc6cc2a15f6e681dc45f7cb029 (patch)
tree8ecfaa79c019a9aa52ab69669e281ff540bfe6df /src/main/scala/chisel3/util/BitPat.scala
parent1b8f84859f2ac2d40085e6c31034dd598a5c6aad (diff)
bitpat should keep the width of uint (#232)
Diffstat (limited to 'src/main/scala/chisel3/util/BitPat.scala')
-rw-r--r--src/main/scala/chisel3/util/BitPat.scala5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/main/scala/chisel3/util/BitPat.scala b/src/main/scala/chisel3/util/BitPat.scala
index 9eb5cf67..d476f957 100644
--- a/src/main/scala/chisel3/util/BitPat.scala
+++ b/src/main/scala/chisel3/util/BitPat.scala
@@ -68,7 +68,8 @@ object BitPat {
*/
def apply(x: UInt): BitPat = {
require(x.isLit)
- BitPat("b" + x.litValue.toString(2))
+ val len = if (x.width.known) x.getWidth else 0
+ apply("b" + x.litValue.toString(2).reverse.padTo(len, "0").reverse.mkString)
}
}
@@ -83,7 +84,7 @@ sealed class BitPat(val value: BigInt, val mask: BigInt, width: Int) {
def =/= (that: UInt): Bool = macro SourceInfoTransform.thatArg
def != (that: UInt): Bool = macro SourceInfoTransform.thatArg
- def do_=== (that: UInt)(implicit sourceInfo: SourceInfo): Bool = UInt(value) === (that & UInt(mask))
+ def do_=== (that: UInt)(implicit sourceInfo: SourceInfo): Bool = UInt(value, width) === (that & UInt(mask))
def do_=/= (that: UInt)(implicit sourceInfo: SourceInfo): Bool = !(this === that)
def do_!= (that: UInt)(implicit sourceInfo: SourceInfo): Bool = this =/= that
}