summaryrefslogtreecommitdiff
path: root/src/main/scala/chisel3/util/BitPat.scala
diff options
context:
space:
mode:
authorJim Lawson2016-12-12 09:14:33 -0800
committerGitHub2016-12-12 09:14:33 -0800
commitb581a24728bfba0c39ed2c032fd86f628a1e1a50 (patch)
treef625219f936d39e760192aa69df17e776b95dd56 /src/main/scala/chisel3/util/BitPat.scala
parent0bd9ae059368570dc72f25f7939afa5cfe5fd06e (diff)
parentad53161bbb9f67e16b88ca7a508a537f88d77e05 (diff)
Merge branch 'master' into buildinfousepackageaspath
Diffstat (limited to 'src/main/scala/chisel3/util/BitPat.scala')
-rw-r--r--src/main/scala/chisel3/util/BitPat.scala21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/main/scala/chisel3/util/BitPat.scala b/src/main/scala/chisel3/util/BitPat.scala
index e58258c7..add40f79 100644
--- a/src/main/scala/chisel3/util/BitPat.scala
+++ b/src/main/scala/chisel3/util/BitPat.scala
@@ -35,7 +35,7 @@ object BitPat {
}
/** Creates a [[BitPat]] literal from a string.
- *
+ *
* @param n the literal value as a string, in binary, prefixed with 'b'
* @note legal characters are '0', '1', and '?', as well as '_' and white
* space (which are ignored)
@@ -45,7 +45,12 @@ object BitPat {
new BitPat(bits, mask, width)
}
- /** Creates a [[BitPat]] of all don't cares of the specified bitwidth. */
+ /** Creates a [[BitPat]] of all don't cares of the specified bitwidth.
+ *
+ * @example {{{
+ * val myDontCare = BitPat.dontCare(4) // equivalent to BitPat("b????")
+ * }}}
+ */
def dontCare(width: Int): BitPat = BitPat("b" + ("?" * width))
@deprecated("Use BitPat.dontCare", "chisel3")
@@ -57,7 +62,7 @@ object BitPat {
*/
def bitPatToUInt(x: BitPat): UInt = {
require(x.mask == (BigInt(1) << x.getWidth) - 1)
- UInt(x.value, x.getWidth)
+ x.value.asUInt(x.getWidth.W)
}
/** Allows UInts to be used where a BitPat is expected, useful for when an
@@ -73,10 +78,14 @@ object BitPat {
}
}
-// TODO: Break out of Core? (this doesn't involve FIRRTL generation)
/** Bit patterns are literals with masks, used to represent values with don't
- * cares. Equality comparisons will ignore don't care bits (for example,
- * BitPat(0b10?1) === 0b1001.asUInt and 0b1011.asUInt.
+ * care bits. Equality comparisons will ignore don't care bits.
+ *
+ * @example {{{
+ * "b10101".U === BitPat("b101??") // evaluates to true.B
+ * "b10111".U === BitPat("b101??") // evaluates to true.B
+ * "b10001".U === BitPat("b101??") // evaluates to false.B
+ * }}}
*/
sealed class BitPat(val value: BigInt, val mask: BigInt, width: Int) {
def getWidth: Int = width