如何在凿子代码中生成随机的 Scala Int?



我正在尝试在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生成的凿子随机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进行索引

最新更新