mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
corelogic/misc: displacer + chooser
This commit is contained in:
parent
e10e4360f3
commit
244bf17db7
1 changed files with 15 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue