genlib/misc: improve genericity of split/displacer/chooser
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 20 Aug 2013 14:52:48 +0000 (16:52 +0200)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Tue, 20 Aug 2013 16:49:02 +0000 (18:49 +0200)
migen/genlib/misc.py

index 97d0be0e07aa6bdd749a3aef7e7c3c167ba2d38a..38d24d191392665c895b562060252b24719c5076 100644 (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)