Question

I read that UInt(1) refers to a 1-bit decimal literal. I'm confused about what UInt(0) could mean. 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?

No correct solution

OTHER TIPS

UInt defines an unsigned integer. 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, 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.

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

UInt(1) refers to a 1-bit literal of value 1.

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

A Mux() essentially performs "lhs = cond ? UInt(0) : n". So if "n" is greater than max, we wrap-around and return the value 0 (of type UInt).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top