chisel中Counter的源码如下,
class Counter(val n: Int) {
require(n >= 0, s"Counter value must be nonnegative, got: $n")
val value = if (n > 1) RegInit(0.U(log2Ceil(n).W)) else 0.U
/** Increment the counter
*
* @note The incremented value is registered and will be visible on the next clock cycle
* @return whether the counter will wrap to zero on the next cycle
*/
def inc(): Bool = {
if (n > 1) {
val wrap = value === (n-1).U
value := value + 1.U
if (!isPow2(n)) {
when (wrap) { value := 0.U }
}
wrap
} else {
true.B
}
}
}
提一个问题:如果将val wrap = value === (n-1).U和value := value + 1.U这二句互换位置,有没有影响???