From 1662e1b3bccfd6efbd6ff7731d890fa493be888e Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 13 Feb 2012 23:10:27 +0100 Subject: [PATCH] corelogic: support reverse in displacer/chooser --- migen/corelogic/misc.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/migen/corelogic/misc.py b/migen/corelogic/misc.py index ba30e66ee..a6374c517 100644 --- a/migen/corelogic/misc.py +++ b/migen/corelogic/misc.py @@ -40,17 +40,27 @@ def split(v, *counts): offset += n return tuple(r) -def displacer(signal, shift, output, n=None): +def displacer(signal, shift, output, n=None, reverse=False): if n is None: n = 2**shift.bv.width w = signal.bv.width - l = [Replicate(shift == i, w) & signal for i in range(n)] + if reverse: + r = reversed(range(n)) + else: + r = range(n) + l = [Replicate(shift == i, w) & signal for i in r] return output.eq(Cat(*l)) -def chooser(signal, shift, output, n=None): +def chooser(signal, shift, output, n=None, reverse=False): if n is None: n = 2**shift.bv.width w = output.bv.width - cases = [[Constant(i, shift.bv), output.eq(signal[i*w:(i+1)*w])] for i in range(n)] + cases = [] + for i in range(n): + if reverse: + s = n - i - 1 + else: + s = i + cases.append([Constant(i, shift.bv), output.eq(signal[s*w:(s+1)*w])]) cases[n-1][0] = Default() return Case(shift, *cases)