I'm trying to find functional equivalent of the following algorithm (not really Scala or Chisel syntax):
val x = Wire(Vec(n, UInt(L.W)))
val z = Wire(UInt(L.W))
var y = 0;
for (i <- 0 to (L-1)) {
y = 0;
for (j <- 0 to (n-1)) {
y = y || x(j, i)
}
z(i) = y;
}
Original Problem
I have n buses, each having L wires. I want to create an OR gate that has respective bits from each bus and produce an output. The reduction operators that I know works on a single bus. For example, I could use x(1).orR to create an OR gate, but how can I achieve this on an array of buses. I'm assuming Chisel requires all hardware-related behavioral models to be functional in nature. So, my question is two fold:
- Do I always need to write behavioral models in Chisel using functional programming?
- Can I create a functional for loop that achieves the above.