summaryrefslogtreecommitdiff
path: root/src/main/scala/chisel3/util/OneHot.scala
diff options
context:
space:
mode:
authorJim Lawson2016-09-23 08:19:43 -0700
committerGitHub2016-09-23 08:19:43 -0700
commit785620b1403d827986bf60c2a001d8d6f71eed72 (patch)
tree1c1a0b14b041e544da3ff8176aba200604a131b3 /src/main/scala/chisel3/util/OneHot.scala
parentb18e98ba2d058c7dd24f96f005486b70c856aeca (diff)
parentdecb2ee0f0bb8223f0b2b067b88ed90b71473a28 (diff)
Merge pull request #291 from ucb-bar/utilscaladocs
Scaladocs for utils
Diffstat (limited to 'src/main/scala/chisel3/util/OneHot.scala')
-rw-r--r--src/main/scala/chisel3/util/OneHot.scala24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/main/scala/chisel3/util/OneHot.scala b/src/main/scala/chisel3/util/OneHot.scala
index 7e04a8d7..53ba8c3d 100644
--- a/src/main/scala/chisel3/util/OneHot.scala
+++ b/src/main/scala/chisel3/util/OneHot.scala
@@ -7,8 +7,12 @@ package chisel3.util
import chisel3._
-/** Converts from One Hot Encoding to a UInt indicating which bit is active
- * This is the inverse of [[Chisel.UIntToOH UIntToOH]]*/
+/** Returns the bit position of the sole high bit of the input bitvector.
+ *
+ * Inverse operation of [[UIntToOH]].
+ *
+ * @note assumes exactly one high bit, results undefined otherwise
+ */
object OHToUInt {
def apply(in: Seq[Bool]): UInt = apply(Cat(in.reverse), in.size)
def apply(in: Vec[Bool]): UInt = apply(in.asUInt, in.size)
@@ -26,9 +30,9 @@ object OHToUInt {
}
}
-/** @return the bit position of the trailing 1 in the input vector
- * with the assumption that multiple bits of the input bit vector can be set
- * @example {{{ data_out := PriorityEncoder(data_in) }}}
+/** Returns the bit position of the least-significant high bit of the input bitvector.
+ *
+ * Multiple bits may be high in the input.
*/
object PriorityEncoder {
def apply(in: Seq[Bool]): UInt = PriorityMux(in, (0 until in.size).map(UInt(_)))
@@ -37,8 +41,7 @@ object PriorityEncoder {
/** Returns the one hot encoding of the input UInt.
*/
-object UIntToOH
-{
+object UIntToOH {
def apply(in: UInt, width: Int = -1): UInt =
if (width == -1) {
UInt(1) << in
@@ -47,11 +50,10 @@ object UIntToOH
}
}
-/** Returns a bit vector in which only the least-significant 1 bit in
- the input vector, if any, is set.
+/** Returns a bit vector in which only the least-significant 1 bit in the input vector, if any,
+ * is set.
*/
-object PriorityEncoderOH
-{
+object PriorityEncoderOH {
private def encode(in: Seq[Bool]): UInt = {
val outs = Seq.tabulate(in.size)(i => UInt(BigInt(1) << i, in.size))
PriorityMux(in :+ Bool(true), outs :+ UInt(0, in.size))