例如,我们假设我有以下数据:
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)
*/
评论中描述了我需要做的事情。是否可以轻松进行此类操作?(例如,使用for循环或其他)
答案 0 :(得分:2)
这个特殊问题很容易在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(_ + _)
}