Search code examples
scalachisel

How to create array of the module? Use Array or Vec?


I found the similar example in https://github.com/ucb-bar/chisel-tutorial/blob/release/src/main/scala/examples/Adder.scala.

However, I am still confused with using Array or Vec method and do not clearly understand the comments from line 15 ~ line 18.

Could anyone explain it more detail? If I want to create array of module, when to use Array and Vec in proper way?


Solution

  • From the Chisel API doc:

    In general Vec only needs to be used when there is a need to express the hardware collection in a Reg or IO Bundle or when access to elements of the array is indexed via a hardware signal.

    Plain Scala collections are equipped with versatile methods and can hold references to hardware, but they can't actually represent hardware. For instance, when indexing the vector of modules using a Chisel node, Vec is needed.

    A brief account of pros and cons of Scala collections versus Vec is available in the Chisel style guide.