I am trying to get the value of a reg and compare it with a number inside and if statement
val refill_addr = Reg(UInt(width = paddrBits))
if ( refill_addr > 20000.U)
cacheable := true
else
cacheable := false
but i get this error
[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
You should be using when
/.otherwise
here instead of if
/else
.
when
is a Chisel (hardware) construct that will eventually map to one or more multiplexers. if
is a Scala construct and can be used for compile-time generation of hardware.
when (refill_addr > 20000.U) {
cacheable := true
} .otherwise {
cacheable := false
}
For some more info, there was a similar question here.