genlib/misc: improve genericity of split/displacer/chooser

This commit is contained in:
Florent Kermarrec 2013-08-20 16:52:48 +02:00 committed by Sebastien Bourdeauducq
parent 6f9f08f6eb
commit 37930d70ac
1 changed files with 8 additions and 1 deletions

View File

@ -24,11 +24,16 @@ def split(v, *counts):
r = []
offset = 0
for n in counts:
r.append(v[offset:offset+n])
if n != 0:
r.append(v[offset:offset+n])
else:
r.append(None)
offset += n
return tuple(r)
def displacer(signal, shift, output, n=None, reverse=False):
if shift is None:
return output.eq(signal)
if n is None:
n = 2**flen(shift)
w = flen(signal)
@ -40,6 +45,8 @@ def displacer(signal, shift, output, n=None, reverse=False):
return output.eq(Cat(*l))
def chooser(signal, shift, output, n=None, reverse=False):
if shift is None:
return output.eq(signal)
if n is None:
n = 2**flen(shift)
w = flen(output)