【问题标题】:How to generate a random Scala Int in Chisel code?如何在 Chisel 代码中生成随机 Scala Int?
【发布时间】:2020-01-29 13:52:41
【问题描述】:

我正在尝试在 RocketChip 核心(有序) 中实现方式预测技术。为此,我需要分别访问每种方式。所以这就是标签的 SRAM 修改后的样子(每路单独的 SRAM)

val tag_arrays = Seq.fill(nWays) { SeqMem(nSets, UInt(width = tECC.width(1 + tagBits)))}
val tag_rdata = Reg(Vec(nWays, UInt(width = tECC.width(1 + tagBits))))
for ((tag_array, i) <- tag_arrays zipWithIndex) {
  tag_rdata(i) := tag_array.read(s0_vaddr(untagBits-1,blockOffBits), !refill_done && s0_valid)
}

我想像这样访问它

when (refill_done) {
  val enc_tag = tECC.encode(Cat(tl_out.d.bits.error, refill_tag))
  tag_arrays(repl_way).write(refill_idx, enc_tag)
  ccover(tl_out.d.bits.error, "D_ERROR", "I$ D-channel error")
}

其中 repl_way 是 LFSR 生成的 Chisel 随机 UInt。但是 Seq 元素只能通过 Scala Int 索引访问,这会导致编译错误。然后我尝试像这样访问它

when (refill_done) {
  val enc_tag = tECC.encode(Cat(tl_out.d.bits.error, refill_tag))
  for (i <- 0 until nWays) {
    when (repl_way === i.U) {tag_arrays(i).write(refill_idx, enc_tag)}
  }
  ccover(tl_out.d.bits.error, "D_ERROR", "I$ D-channel error")
}

但是断言出现了 -

assert(PopCount(s1_tag_hit zip s1_tag_disparity map { case (h, d) => h && !d }) <= 1)

我正在尝试修改 ICache.scala 文件。关于如何正确执行此操作的任何想法?谢谢!

【问题讨论】:

  • 产生上述断言的原因是我试图在一个向量寄存器中收集所有方式的标签,然后在下一个周期将它们与传入的标签进行比较,而原始解决方案正在读取所有方式一次进入一个向量并在同一周期比较它们以定义缓存命中或未命中。现在,我只是将每个标签读入一个单独的变量,然后初始化一个向量(即 4 种方式 - 4 个变量 - 4 个元素的 Vec)。 data_arrays 也是如此。它有效,我的意思是,我可以分别访问每种方式并​​选择访问哪种方式,但它不再是通用的。

标签: scala riscv chisel rocket-chip


【解决方案1】:

我认为你可以在这里使用Vec 而不是Seq

val tag_arrays = Vec(nWays, SeqMem(nSets, UInt(width = tECC.width(1 + tagBits))))

Vec 允许使用 UInt 进行索引

【讨论】:

  • 感谢您的回答,但 Vec 不支持 SeqMem 作为参数。 ICache.scala:181:20:重载方法值适用于替代方案:[error] [T <: chisel.data t elts:> [error] [T <: chisel.data t n: int compileoptions: chisel3.core.compileoptions> [error] [T <: chisel3.core.data int gen: t sourceinfo: chisel3.internal.sourceinfo.sourceinfo compileoptions: chisel3.core.compileoptions chisel3.core.syncreadmem>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-18
  • 2011-08-19
  • 2014-05-21
  • 2010-09-13
相关资源
最近更新 更多