Reputation: 55
class CC extends Module {
val io = IO(new Bundle {
val in1 = Input(Vec(5, UInt(3.W)))
val in2 = Input(Vec(5, UInt(3.W)))
val out = Output(Vec(9, UInt(3.W)))
})
val L = 5
val ml = 4
var y = 0
for (i <- 0 until ml) {
when (io.in2(i) === io.in1(L - ml + i))
y = y + 1
}
when (y === ml) {
io.out := Cat(io.in1(0) ,io.in2)
}
io.out := io.in1
}
This is the code for concatenating two strings after checking if they match or not. For example, if the in1 is 1001 and in2 is 0010, it has to concatenate and return 10010
Also, I have a couple of questions
1) Can we concatenate vectors?
2) Is '===' operator valid for vectors?
3) Can we compare two vectors?
The errors I get
1)
inferred type arguments [chisel3.core.Data] do not conform to method apply's type parameter bounds [T <: chisel3.Bits] [error] io.out := Cat(io.in1(0) ,io.in2)
2)
value === is not a member of Int [error] when (y === ml)
3)
type mismatch; [error] found : chisel3.core.UInt [error] required: T [error] io.out := Cat(io.in1(0) ,io.in2)
Can somebody guide me? Thank you!
Upvotes: 2
Views: 1659
Reputation: 3761
Lots of confusion in this code.
First 'y' should be a Chisel register, not a scala Int variable.
val y = RegInit(0.asUInt(8.W))
Scala for loop is used as GENERATE in VHDL, it's for 'copying' some code line.
Then as I understand this loop :
for (i <- 0 until ml){
when (io.in2(i) === io.in1(L.U - ml.U + i))
y = y + 1
}
In fact the value 'y' should be a Vector :
val y = RegInit(VecInit(Seq.fill(m1)(0.asUInt(8.W))))
And your loop should look like this :
for (i <- 0 until ml){
when (io.in2(i) === io.in1(L - ml + i)){
y(i) := y(i) + 1.U
}
io.out(i) := 0.U
when (y(i) === ml){
io.out(i) := io.in2(i)
}
}
io.out(m1+1) := io.in1(0)
io.out should be Vec size of 6 and not 9:
val out = Output(Vec(6, UInt(3.W)))
Upvotes: 2