繁体   English   中英

如何在 Chisel 代码中生成一个随机的 Scala Int?

[英]How to generate a random Scala Int in Chisel code?

我正在尝试在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文件。 关于如何正确执行此操作的任何想法? 谢谢!

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

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

Vec 允许使用UInt进行索引

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM