Beispiel #1
0
def test_mux():
    c = hl.Var()
    f = hl.Func()
    f[c] = hl.mux(c, [123, 456, c])
    b = f.realize(4)
    assert b[0] == 123
    assert b[1] == 456
    assert b[2] == 2
    assert b[3] == 3
Beispiel #2
0
def test_mux_tuple():
    f = hl.Func()
    g = hl.Func()
    x = hl.Var()
    c = hl.Var()
    g[x] = (123, 456, x)
    f[x, c] = hl.mux(c, g[x])
    b = f.realize(1, 4)
    assert b[0, 0] == 123
    assert b[0, 1] == 456
    assert b[0, 2] == 0
    assert b[0, 3] == 0
Beispiel #3
0
 def maybe_mux(s):
     '''wrap multiple Exprs in mux()'''
     if len(set(s)) == 1:
         return s[0]
     else:
         return hl.mux(hl.Expr(ru), s)