From: Sebastien Bourdeauducq Date: Sat, 11 Feb 2012 19:57:08 +0000 (+0100) Subject: corelogic/misc: displacer + chooser X-Git-Tag: 24jan2021_ls180~2099^2~1029 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=244bf17db7b7cc8b0239d2cd8ac27d6f9707931a;p=litex.git corelogic/misc: displacer + chooser --- diff --git a/migen/corelogic/misc.py b/migen/corelogic/misc.py index 7705e507..0140deb6 100644 --- a/migen/corelogic/misc.py +++ b/migen/corelogic/misc.py @@ -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)