2

我正在尝试获取 reg 的值并将其与内部的数字和 if 语句进行比较

  val refill_addr    = Reg(UInt(width = paddrBits))
if ( refill_addr >  20000.U) 
   cacheable := true
   else 
       cacheable := false

但我得到这个错误

[error] /home/a/i-rocket-chip/src/main/scala/rocket/ICache.scala:365:18: type mismatch;
[error]  found   : chisel3.core.Bool
[error]  required: Boolean
[error] if ( refill_addr >  20000.U) 
[error]                  ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

4

2 回答 2

4

您应该在这里使用when/.otherwise而不是if/ else

when是一种 Chisel(硬件)结构,最终将映射到一个或多个多路复用器。if是一个 Scala 结构,可用于硬件的编译时生成。

when (refill_addr >  20000.U) {
  cacheable := true
} .otherwise {
  cacheable := false
}

有关更多信息,这里有一个类似的问题

于 2019-05-27T17:59:08.530 回答
0

另一个方便且经过 FIRRTL 优化的解决方案是使用Mux

val cacheable = Mux(refill_addr > 20000.U, true.B, false.B)

对于更复杂的表达式和用例,您可以查看本指南

于 2020-02-04T15:56:31.597 回答