【问题标题】:comparing the value in a register to an int将寄存器中的值与 int 进行比较
【发布时间】:2019-05-27 16:50:05
【问题描述】:

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

【问题讨论】:

    标签: chisel rocket-chip


    【解决方案1】:

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

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

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

    更多信息,there was a similar question here

    【讨论】:

    • 当我这样做时,我得到了这个错误而不是Exception in thread "main" firrtl.passes.PassExceptions: firrtl.passes.CheckChirrtl$InvalidLOCException: @[ICache.scala 367:14:freechips.rocketchip.system.DefaultConfig.fir@212151.6]: [module ICache] Invalid connect to an expression that is not a reference or a WritePort. firrtl.passes.CheckChirrtl$InvalidLOCException: @[ICache.scala 370:18:freechips.rocketchip.system.DefaultConfig.fir@212154.6]: [module ICache] Invalid connect to an expression that is not a reference or a WritePort. firrtl.passes.PassException: 2 errors detected!
    • 这表明您正在尝试连接到您无法连接到的东西(语句左侧的东西)。由于您所做的修改,这听起来像是用户错误。这可能是由于您声明 cacheable 的方式。这应该是寄存器、线路或内存端口,但 FIRRTL 编译器表明它不是。您可以通过查看ICache.scala 的第 370 行或生成的 FIRRTL 的第 212154 行来开始调试。
    【解决方案2】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-02
      • 2020-11-15
      • 2020-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多