0
votes

In Scala one way we could declare an ArrayBuffer of array of Doubles,Long and Boolean is as such:

val A = new ArrayBuffer[Array[(Long, Array[Double], Array[Double], Double, Boolean)]]

I would like to do same in chisel.
In chisel I know one way of declaring a vector of length n as input is as follows:

val X  = Input(Vec(n,FixedPoint(16.W, 8.BP)))

where n is Int, And this works .
Now I tried to initialise an array of n FixedPoint too, and did the following:

   val C = Array(Array.ofDim(FixedPoint(16.W, 8.BP)))(n,0)

Inspired from initialisation of an array

But this did not work. I get the error

    type mismatch;
[error]  found   : chisel3.core.FixedPoint
[error]  required: Int
[error]    val tabHash1 = Array(Array.ofDim(FixedPoint(16.W, 8.BP)))(n,0)

Please, can someone give the correct way of declaring A above of FixedPoint, and an Array of FixedPoint numbers in chisel? Thanks! for your attention and your responses.

1

1 Answers

0
votes

Chisel will follow the ordinary rules of Scala collection declarations. I am not sure what you are trying to create here but the parameters are not quite right Array.ofDim is for creating multi-dimensional arrays, so if you are trying to create a 2 dimensional array of FixedPoint you want.

val C = Array.ofDim[FixedPoint](m, n)

Where n and m are the sizes in the two dimensions. You have wrapped the Array.ofDim in another Array, so maybe you actually want a 3 dimensional array of FixedPoint, which would be

    val C = Array.ofDim[FixedPoint](k, m, n)

Both of these techniques will give arrays that have all the slots for FixePoint but they will not be filled in, so probably what you really want is

val C = Array.fill(k, m, n)(FixedPoint(16.W, 8.BP)

You can then wire these FixedPoints together how ever you want.

C(0, 0,0) := C(1, 1, 1) + C(2, 2, 2)

might be an example.

If you need to access your FixedPoint elements using hardware indexing you will need a Vec instead of an Array. The easiest way to initialize Vec is with a Seq of Elements. A 2 dimensional Vec of FixedPoint could be created with

val c = Vec(Seq.fill(n)(Vec(Seq.fill(m)(FixedPoint(16.W, 8.BP)))))

I would suggest looking at Scala Land vs Chisel Land for some background on using Chisel in Scala.