【问题标题】:What does UInt(0) mean?UInt(0) 是什么意思?
【发布时间】:2013-10-16 17:50:01
【问题描述】:

我读到 UInt(1) 指的是 1 位十进制文字。我对 UInt(0) 的含义感到困惑。它用于计数器代码,如下所示:-

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   
    }

有人可以解释这两个突出显示(以星号为界)语句的工作原理吗?

【问题讨论】:

    标签: scala hardware hdl uint chisel


    【解决方案1】:

    UInt 定义一个无符号整数。 UInt(value) 定义了一个 1 位十进制文字,因此 UInt(0)UInt(1) 是分别包含 0 和 1 的 1 位宽整数的文字。 UInt(value, width) 允许您定义值大于 1 位的文字,因此从您的示例中 UInt(0, max.getWidth) 创建一个无符号整数,其中 max.getWidth 位保持值 0。

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

    【讨论】:

      【解决方案2】:

      UInt(1) 指的是一个 1 位文字值为 1

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

      Mux() 本质上执行“lhs = cond ? UInt(0) : n”。因此,如果“n”大于最大值,我们将返回值 0(UInt 类型)。

      【讨论】:

        猜你喜欢
        • 2015-03-20
        • 2020-01-07
        • 2018-09-10
        • 2017-05-09
        • 2018-09-25
        • 2011-05-25
        • 2010-11-20
        • 1970-01-01
        相关资源
        最近更新 更多