我是Scala的新生,并打算研究火箭的源代码(由Scala / Chisel开发),并且我不理解下面的案例类源代码。我的问题是,当我们引用reg_cycle时,返回的值是什么(值?)?并且您可以做一些介绍为什么在Scala中发生这种情况吗?
//source code for how to use case calss
val reg_instret = WideCounter(64, io.retire)
val reg_cycle = if (enableCommitLog) reg_instret else WideCounter(64)
if (xLen == 32) {
read_mapping += CSRs.mcycleh -> (**reg_cycle** >> 32)
read_mapping += CSRs.minstreth -> (reg_instret >> 32)
if (usingUser) {
read_mapping += CSRs.cycleh -> (reg_cycle >> 32)
read_mapping += CSRs.instreth -> (reg_instret >> 32)
}
}
//source code for case calss
case class WideCounter(width: Int, inc: UInt = UInt(1), reset: Boolean = true)
{
private val isWide = width > 2*inc.getWidth
private val smallWidth = if (isWide) inc.getWidth max log2Up(width) else width
private val small = if (reset) Reg(init=UInt(0, smallWidth)) else Reg(UInt(width = smallWidth))
private val nextSmall = small +& inc
small := nextSmall
private val large = if (isWide) {
val r = if (reset) Reg(init=UInt(0, width - smallWidth)) else Reg(UInt(width = width - smallWidth))
when (nextSmall(smallWidth)) { r := r + UInt(1) }
r
} else null
val value = if (isWide) Cat(large, small) else small
lazy val carryOut = {
val lo = (small ^ nextSmall) >> 1
if (!isWide) lo else {
val hi = Mux(nextSmall(smallWidth), large ^ (large +& UInt(1)), UInt(0)) >> 1
Cat(hi, lo)
}
}
def := (x: UInt) = {
small := x
if (isWide) large := x >> smallWidth
}
}
答案 0 :(得分:1)
reg_cycle是WideCounter。根据记录的布尔值将其初始化为不同的特定实例。
WideCounter有几个字段,可以通过它们的名称,宽度,公司和重置来访问。