summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main
diff options
context:
space:
mode:
authorAndrew Waterman2016-07-15 00:09:05 -0700
committerAndrew Waterman2016-07-15 00:09:05 -0700
commit8fc61aeab7c50a5bf2ff6f6f8ab46e960cce2adf (patch)
tree603ab7f1c8453b14c7893b2956cac2296ba809a8 /chiselFrontend/src/main
parentbb5467fc67d3b8fc6cc2a15f6e681dc45f7cb029 (diff)
Improve PopCount implementation
Clean up Scala code, and use +& to generate a lot less FIRRTL
Diffstat (limited to 'chiselFrontend/src/main')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala12
1 files changed, 4 insertions, 8 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala b/chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala
index 91cb9e89..0872ec41 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala
@@ -23,14 +23,10 @@ private[chisel3] object SeqUtils {
/** Counts the number of true Bools in a Seq */
def count(in: Seq[Bool]): UInt = macro SourceInfoTransform.inArg
- def do_count(in: Seq[Bool])(implicit sourceInfo: SourceInfo): UInt = {
- if (in.size == 0) {
- UInt(0)
- } else if (in.size == 1) {
- in.head
- } else {
- count(in.slice(0, in.size/2)) + (UInt(0) ## count(in.slice(in.size/2, in.size)))
- }
+ def do_count(in: Seq[Bool])(implicit sourceInfo: SourceInfo): UInt = in.size match {
+ case 0 => UInt(0)
+ case 1 => in.head
+ case n => count(in take n/2) +& count(in drop n/2)
}
/** Returns data value corresponding to first true predicate */