Как добавить каждый элемент Vec?
Например, предположим, что у меня есть следующие данные:
class VectorElemAdd extends Module {
val io = IO (new Bundle {
val input = Input(Vec(64, UInt(64.W)))
val out = Output(UInt(64.W))
})
/*
if the vector data is : 0, 1, 2, 3, 4, 5, ..., 63,
I have to add each element : 0 + 1 + 2 + ... + 63 by indexing Vec,
for example : input(0) + input(1) + ... + input(63),
But, it needs kind of for loop to add all elements of Vec
and the final output(io.out) will be the input(0) + input(1) + ... +
input(63)
*/
То, что мне нужно сделать, описано в комментарии. Можно ли легко выполнить такую операцию?(Например, использовать цикл или что-то еще)
1 ответ
Решение
Эта конкретная проблема очень легко представить в Scala.
class VectorElemAdd extends Module {
val io = IO (new Bundle {
val input = Input(Vec(64, UInt(64.W)))
val out = Output(UInt(64.W))
})
io.out := io.input.reduce(_ + _)
}