简体   繁体   English

UInt(0)是什么意思?

[英]What does UInt(0) mean?

I read that UInt(1) refers to a 1-bit decimal literal. 我读到UInt(1)指的是1位十进制文字。 I'm confused about what UInt(0) could mean. 我对UInt(0)的含义感到困惑。 It is used in a Counter code that goes as follows :- 它用在如下的计数器代码中:

package TutorialSolutions

    import Chisel._

    object Counter {`

    `def wrapAround(n: UInt, max: UInt) = `    

        Mux(n > max, **UInt(0)**, n)

        // ---------------------------------------- \\
        // Modify this function to increment by the
        // amt only when en is asserted
        // ---------------------------------------- \\
        def counter(max: UInt, en: Bool, amt: UInt) = {     
        val x = Reg(init=**UInt(0, max.getWidth)**)
        when (en) { x := wrapAround(x + amt, max) }


        x   
    }

Can someone explain the working of the two highlighted (bounded by asterisks) statements? 有人可以解释两个突出显示(以星号为界)的语句的工作吗?

UInt defines an unsigned integer. UInt定义一个无符号整数。 UInt(value) defines a 1-bit decimal literal, so UInt(0) and UInt(1) are the literals for 1-bit wide integers holding 0 and 1 respectively. UInt(value)定义了一个1位十进制文字,因此UInt(0)UInt(1)是分别持有0和1的1位宽整数的文字。 UInt(value, width) allows you to define literals with values greater than 1-bit, so from your example UInt(0, max.getWidth) creates an unsigned integer with max.getWidth bits holding the value 0. UInt(value, width)允许您定义值大于1位的文字,因此从示例UInt(0, max.getWidth)创建一个无符号整数, max.getWidth位保持值为0。

Reference: https://chisel.eecs.berkeley.edu/2.0.0/manual.html 参考: https : //chisel.eecs.berkeley.edu/2.0.0/manual.html

UInt(1) refers to a 1-bit literal of value 1 . UInt(1)引用值为1的1位文字。

Mux (n > max, UInt(0), n)

A Mux() essentially performs "lhs = cond ? UInt(0) : n". Mux()本质上执行“ lhs = cond?UInt(0):n”。 So if "n" is greater than max, we wrap-around and return the value 0 (of type UInt). 因此,如果“ n”大于最大值,我们将进行环绕并返回值0(UInt类型)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM