我正在尝试获取 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 构造,可用于硬件的编译时生成。
when (refill_addr > 20000.U) {
cacheable := true
} .otherwise {
cacheable := false
}
有关更多信息,there was a similar question here .
关于chisel - 将寄存器中的值与 int 进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56329835/