chisel - 如何在chisel中自由给vec类型变量赋值?

标签 chisel

我定义了一些向量变量。

val r_parameters = Wire(Vec(RANK, UInt(log2Ceil(RANK).W)))
val test0  = Wire(Vec(RANK, UInt(width.W)))
val test1  = Wire(Vec(RANK, UInt(width.W)))

我尝试使用for循环进行赋值。

for (i <- 0 to RANK-1)
{
    test0(r_parameters(i)) := test1(i)
}

变量“r_parameters”来自 rom 或 ram。如果参数“RANK”为 4,则 r_parameters 的形式为“0 3 2 1”或“0 1 2 3”。这样所有的test0都被分配了。但 firrtl 编译器报告 test0 未完全初始化。

最佳答案

我认为问题在于 firrtl 编译器无法确定 test0 的每个元素都已初始化为某些内容。我已经填写了您的示例,并提供了一些值和一些风格上的更改。

class Wires extends MultiIOModule {
  val RANK = 4
  val bits = 8

  // set to 0, 3, 2, 1
  val r_parameters = VecInit(Seq(0, 3, 2, 1).map(_.U) )

  val test0  = Wire(Vec(RANK, UInt(bits.W)))

  // Give values to test1
  val test1  = VecInit(Seq.tabulate(RANK) { i => i.U } )

  // Wire test1 into test using the map provided by r_parameters
  for (i <- test0.indices) {
    test0(r_parameters(i)) := test1(i)
  }
}

如果你转储发出的 firrtl

println((new ChiselStage).emitFirrtl(new Wires))

你会看到

test0[r_parameters[0]] <= test1[0] @[MemBank.scala 56:28]
test0[r_parameters[1]] <= test1[1] @[MemBank.scala 56:28]
test0[r_parameters[2]] <= test1[2] @[MemBank.scala 56:28]
test0[r_parameters[3]] <= test1[3] @[MemBank.scala 56:28]

Firrtl 无法确认 r_parameters 已彻底连接 test0。

一个重要的问题是你是否需要让 r_parameters 是一个 Vec 而不仅仅是一个 Seq。如果将上面的 r_parameters 更改为

val r_parameters = Seq(0, 3, 2, 1)

模块将正确编译。我怀疑这就是你想要的。如果你确实需要 r_parameters 成为动态索引并且你需要重构你的代码。可以添加

test0 := DontCare

在你的循环前面,但在这种情况下我不推荐它。 希望这对您有所帮助,祝您凿凿愉快!

关于chisel - 如何在chisel中自由给vec类型变量赋值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64265326/

相关文章:

scala - 解决大型 Chisel 文件所触发的 JVM 代码大小限制的任何方法

java - Chisel 的推荐 Java/Scala 设置

chisel - 是否可以在 Chisel 中翻转模拟值?

reset - 异步 negedge 重置的可能解决方法?

chisel - 如何调用内部定义的变量 withClockAndReset

scala - 在 Chisel 中实现 Verilog $onehot 任务

scala - 如何理解这行凿子代码

chisel - Chisel3.2上的文件导入

scala - 引用未完全初始化

verilog - 如何在Chisel3中进行门级仿真?