凿子 hdl 矢量范围分配

chisel hdl vector range assignment

我是 Chisel HDL 的新手。我有一个关于 Vec 赋值的问题。假设我有一个 Vec 有 n 个元素,每个元素都有 w 位 SInt,

如何分配一系列元素,假设我有两个 Vec:a = Vec(10, SInt(width=8)),我有 b = Vec(3, SInt(width=8)),我如何分配 b := a(2:4)

我知道我可以在for循环中做到这一点,有没有更优雅的方式来做到这一点?我没有在上面找到任何示例代码或资料

for (i <- 3 to 8) { my_vec(i) := something_at_index(i) }

您似乎在寻找 Vec 中的切片函数。掠过 Vec class 我找不到这样的函数。

所以简短的回答是否定的,没有开箱即用的优雅方法。

第二个最优雅的事情就是把这样一个函数 在你项目的 util 库中并最终尝试 将此功能上游。

在 Chisel3 中实现它可能看起来像这样:

class FooTester extends BasicTester {
  def slice[T <: Data](someVec: Vec[T], startIndex: Int, endIndex: Int) : Vec[T] = {
    Vec( for (i <- startIndex to endIndex) yield someVec(i) )
  }

  // An initialized Vec
  val a = Vec(
    Range(0, 10)
      .map(SInt(_, width=8))
  )

  // A declared Vec
  val b = Wire(Vec(3, SInt(width=8)))

  b := slice(a, 2, 4)

  assert(b(1) === SInt(3, width=8))

  when(Counter(10).inc()) {stop()}
}