Example #1
0
def Decode(i, n, invert=False, **kwargs):
    """
    Decode the n-bit number i.

    @return: 1 if the n-bit input equals i
    """

    if n <= 4:
        i = 1 << i
        if invert:
            mask = (1 << (1 << n)) - 1
            i = mask & (~i)
        return m.uncurry(LUT(i, n, **kwargs))

    return DefineDecode(i, n)()
Example #2
0
def Decode(i, n, invert=False, **kwargs):
    """
    Decode the n-bit number i.

    @return: 1 if the n-bit input equals i
    """

    assert n <= 8

    if os.environ["MANTLE"] == "coreir":
        from mantle import eq
        from magma import Bits, In, Bit, DefineCircuit, EndDefine, wire, bits, Out
        circ = DefineCircuit(f"Decode{i}{n}", "I", In(Bits(n)), "O", Out(Bit))
        wire(circ.O, eq(circ.I, bits(i, n)))
        EndDefine()
        return circ()
    i = 1 << i
    if invert:
        m = 1 << n
        mask = (1 << m) - 1
        i = mask & (~i)
    return uncurry(LUT(i, n, **kwargs))
Example #3
0
def ROM4(data, i, width):
    return fork([uncurry(LUT(data[i][w], 4)) for w in range(width)])
Example #4
0
 def definition(io):
     swap = uncurry(fork(And(2), Or(2)), prefix="I")
     #swap = uncurry( fork( And(2), Or(2) ) , prefix="in")
     wire(swap(io.I), io.O)