corelogic/misc: displacer + chooser
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Sat, 11 Feb 2012 19:57:08 +0000 (20:57 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Sat, 11 Feb 2012 19:57:08 +0000 (20:57 +0100)
migen/corelogic/misc.py

index 7705e507d7ff4b89eae6e889b09a2ecbbbf86bb5..0140deb694480506adcacc9aaf9eeb6756c00174 100644 (file)
@@ -39,3 +39,18 @@ def split(v, *counts):
                r.append(v[offset:offset+n])
                offset += n
        return tuple(r)
+
+def displacer(signal, shift, output, n=None):
+       if n is None:
+               n = 2**shift.bv.width
+       w = signal.bv.width
+       l = [Replicate(shift == i, w) & signal for i in range(n)]
+       return output.eq(Cat(*l))
+
+def chooser(signal, shift, output, n=None):
+       if n is None:
+               n = 2**shift.bv.width
+       w = signal.bv.width
+       cases = [[Constant(i, shift.bv), output.eq(signal[i*w:i*(w+1)])] for i in range(n)]
+       cases[n-1][0] = Default()
+       return Case(shift, *cases)