summaryrefslogtreecommitdiff
path: root/src/main/scala/Chisel/Cat.scala
diff options
context:
space:
mode:
authorAndrew Waterman2015-10-26 19:07:17 -0700
committerAndrew Waterman2015-10-26 19:07:17 -0700
commit69f41d6892549ef59a3c21cb05d355ea7523c5a2 (patch)
tree56f5811215013cc27e66298da9c71099cd6a86e0 /src/main/scala/Chisel/Cat.scala
parent1b376ed6de722ffe8c3e533e4bf5d964639242e7 (diff)
parent4b51975ec7a543e165660d654fa84eaa9b9b3b3e (diff)
Merge pull request #39 from ucb-bar/coresplit
Break Core.scala into bite-sized pieces
Diffstat (limited to 'src/main/scala/Chisel/Cat.scala')
-rw-r--r--src/main/scala/Chisel/Cat.scala31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main/scala/Chisel/Cat.scala b/src/main/scala/Chisel/Cat.scala
new file mode 100644
index 00000000..8075c11d
--- /dev/null
+++ b/src/main/scala/Chisel/Cat.scala
@@ -0,0 +1,31 @@
+// See LICENSE for license details.
+
+package Chisel
+import Builder.pushOp
+import PrimOp._
+
+// REVIEW TODO: Should the FIRRTL emission be part of Bits, with a separate
+// Cat in stdlib that can do a reduction among multiple elements?
+object Cat {
+ /** Combine data elements together
+ * @param a Data to combine with
+ * @param r any number of other Data elements to be combined in order
+ * @return A UInt which is all of the bits combined together
+ */
+ def apply[T <: Bits](a: T, r: T*): UInt = apply(a :: r.toList)
+
+ /** Combine data elements together
+ * @param r any number of other Data elements to be combined in order
+ * @return A UInt which is all of the bits combined together
+ */
+ def apply[T <: Bits](r: Seq[T]): UInt = {
+ if (r.tail.isEmpty) {
+ r.head.asUInt
+ } else {
+ val left = apply(r.slice(0, r.length/2))
+ val right = apply(r.slice(r.length/2, r.length))
+ val w = left.width + right.width
+ pushOp(DefPrim(UInt(w), ConcatOp, left.ref, right.ref))
+ }
+ }
+}