Let's say I have a Vec of Bool. I want to fill a new Vec of the same size with values equal to a number of true values I've seen up to this index in the original Vec. I want to do it combinationally.
With my HLS background and coding style settled in my head, I want to write something like this:
def foo ( in : Vec[UInt] ) = {
val out = Vec.fill(in.size) {UInt(in.size)}
val nextInd = Wire(init = 0.U)
in.zipWithIndex.foreach {case(val, ind) =>
when(val === true.B) {
out(ind) := nextInd
nextInd := Wire(init = nextInd+1.U)
}
}
}
But I understand this is creating a combinational loop, but I can't find a good way to model it. Somehow I need to generate a new variable iteration of the loop and pass it between iterations.