如何添加 Vec 的每个元素?
How to add each element of 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)
*/
评论中描述了我需要做的事情。是否可以很容易地进行这种操作?(例如,使用for循环或其他)
这个特殊问题在 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(_ + _)
}
例如,假设我有以下数据:
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循环或其他)
这个特殊问题在 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(_ + _)
}