genlib/misc: improve genericity of split/displacer/chooser
This commit is contained in:
parent
6f9f08f6eb
commit
37930d70ac
|
@ -24,11 +24,16 @@ def split(v, *counts):
|
||||||
r = []
|
r = []
|
||||||
offset = 0
|
offset = 0
|
||||||
for n in counts:
|
for n in counts:
|
||||||
|
if n != 0:
|
||||||
r.append(v[offset:offset+n])
|
r.append(v[offset:offset+n])
|
||||||
|
else:
|
||||||
|
r.append(None)
|
||||||
offset += n
|
offset += n
|
||||||
return tuple(r)
|
return tuple(r)
|
||||||
|
|
||||||
def displacer(signal, shift, output, n=None, reverse=False):
|
def displacer(signal, shift, output, n=None, reverse=False):
|
||||||
|
if shift is None:
|
||||||
|
return output.eq(signal)
|
||||||
if n is None:
|
if n is None:
|
||||||
n = 2**flen(shift)
|
n = 2**flen(shift)
|
||||||
w = flen(signal)
|
w = flen(signal)
|
||||||
|
@ -40,6 +45,8 @@ def displacer(signal, shift, output, n=None, reverse=False):
|
||||||
return output.eq(Cat(*l))
|
return output.eq(Cat(*l))
|
||||||
|
|
||||||
def chooser(signal, shift, output, n=None, reverse=False):
|
def chooser(signal, shift, output, n=None, reverse=False):
|
||||||
|
if shift is None:
|
||||||
|
return output.eq(signal)
|
||||||
if n is None:
|
if n is None:
|
||||||
n = 2**flen(shift)
|
n = 2**flen(shift)
|
||||||
w = flen(output)
|
w = flen(output)
|
||||||
|
|
Loading…
Reference in New Issue