summaryrefslogtreecommitdiff
path: root/src/main/scala/Chisel/Cat.scala
blob: 8075c11dc52851356e12c4d7c8a9a3cfeac527c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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))
    }
  }
}