Vec considered harmful; use isOneOf instead (#64)
Vec is heavyweight and really should only be used for I/O and
dynamic indexing. A recurring pattern in uncore is
Vec(const1, const2, const3) contains x
which is nice but has a deleterious effect on simulation copilation
and execution time. This patch proposes an alternative:
x isOneOf (const1, const2, const3)
x isOneOf seqOfThings
I think it's also more idiomatic.
This is just a prototype; I'm not wed to the name or implementation.
This commit is contained in:
1 parent
16a6b11081
commit
70b677ecda
6 files changed
+73
-57
No files matched your search
@@ -0,0 +1,11 @@
|
||||
package uncore
|
||||
|
||||
import Chisel._
|
||||
|
||||
package object Util {
|
||||
implicit class UIntIsOneOf(val x: UInt) extends AnyVal {
|
||||
def isOneOf(s: Seq[UInt]): Bool = s.map(x === _).reduce(_||_)
|
||||
|
||||
def isOneOf(u1: UInt, u2: UInt*): Bool = isOneOf(u1 +: u2.toSeq)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user