6

I am learing Chisel3.

I have some questions about the codes.

val myVec = Wire(Vec(5, SInt(width = 23)))  // Vector of 5 23-bit signed integers.

I thought if I declare a vector and I need to write "Wire",but I was wrong when I saw these codes.

class BigBundle extends Bundle {


 val myVec = Vec(5, SInt(width = 23))  // Vector of 5 23-bit signed integers.

 val flag  = Bool()
 // Previously defined bundle.

 val f     = new MyFloat

}

It punchs on my face suddenly,so I want to know when do I use "Wire"?

Thanks in advance.

FabienM
  • 3,421
  • 23
  • 45
jjlin
  • 111
  • 7

2 Answers2

6

The key here is the distinction in Chisel3 between "types" and "values."

Vec, Bundle, UInt, SInt, and Bool are examples of "types."

Wire, Reg, Input, Output, and Mem are examples of "values."

With BigBundle from the above:

class BigBundle extends Bundle {
  val myVec = Vec(5, SInt(23.W)) // Vector of 5 23-bit signed integers.
  val flag = Bool()
  val f = new MyFloat // Previously defined bundle.
}

BigBundle is a "type" just like Vec(5, SInt(23.W)) is a "type."

If you wish to use these types you can create a Wire of one of these types, eg.

val myVecWire = Wire(Vec(5, SInt(23.W)))
val myBundleWire = Wire(new BigBundle)

EDIT: Updated for modern chisel3 style

Jack Koenig
  • 5,840
  • 15
  • 21
  • Can you give an example of how to do operation to myBundleWire?It could make me more understand. – jjlin Nov 29 '16 at 04:22
  • You can access the fields of a Wire (or other value) of type BigBundle using dot notation and connect to them with the connection operator `:=`. Thus if you want to connect the flag field of myBundleWire to false you could write the following: `myBundleWire.flag := false.B` – Jack Koenig Nov 29 '16 at 19:05
  • Thanks I totally understood. – jjlin Nov 30 '16 at 05:06
4

You use Wire for any Chisel node that you might reassign the value of.

val a = Wire(Bool())
a := Bool(false)
...
Chris
  • 3,827
  • 22
  • 30