将寄存器中的值与 int 进行比较

comparing the value in a register to an int

我正在尝试获取 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

您应该在此处使用 when/.otherwise 而不是 if/else

when 是一种 Chisel(硬件)构造,最终将映射到一个或多个多路复用器。 if 是一个 Scala 构造,可用于 compile-time 生成硬件。

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

有关更多信息,there was a similar question here

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

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

对于更复杂的表达式和用例,您可以查看 this guide