2
votes

I am new to this.

I have some questions about the code.

What is different between these codes:

val myVec = Vec(5){Fix(width= 23)}

and

val myVec = Vec.fill(5){SInt(width = 23 )}

what does "fill" mean?

thanks

1

1 Answers

2
votes

"Fill" is a Scala-ism, for initializing things like lists with elements:

scala> val x = List.fill(3)("foo")
x: List[java.lang.String] = List(foo, foo, foo)

In the same vein, Vec.fill(5){SInt(width=23)} is returning a Chisel Vec where each of the 5 elements is set to a 23b signed integer wire.


However, if you are using Chisel, you should move to Chisel3 (https://github.com/ucb-bar/chisel3/wiki), in which the new syntax is:

val myVec = Wire(Vec(5, SInt(width=23)))

That creates a Wire of a 5-element vector made up of 23b signed integers. (In Chisel3 any wires must be explicitly wrapped).