From 4cec4fbd045d7193d94adc423359144d2210cf5d Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sun, 12 Dec 2021 14:32:24 +0000 Subject: [PATCH] remove the pre-added array, remove the sub-function (sub-functions are a bit... naff), accumulate the list on-demand, provide comments about what that list is for --- src/nmutil/grev.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/nmutil/grev.py b/src/nmutil/grev.py index a0c3555..c5206e6 100644 --- a/src/nmutil/grev.py +++ b/src/nmutil/grev.py @@ -30,29 +30,31 @@ class GRev(Elaboratable): def elaborate(self, platform): m = Module() - # XXX internal signals do not need to be members of the module. - # more to the point: why is the array needed at all? just - # assign step_i = self.input outside the loop, create one - # step_o Signal at the start and assign step_i=step_o at the end - def step(i): - return Signal(self.width, name=f"step{i}") - _steps = [step(i) for i in range(self.log2_width)] + _steps = [] # cumulative list of steps (for unit test purposes only) + + step_i = self.input # start combinatorial chain with the input # TODO: comment that this creates a full combinatorial chain # of RADIX-2 butterfly-network "swappers" for i, step_o in enumerate(_steps): - step_i = self.input if i == 0 else _steps[i - 1] + step_o = Signal(self.width, name="step_%d" % i) + _steps.append(step_o) # TODO explain that chunk swap-sizes jump by a power2 each time chunk_size = 1 << i # TODO comment that this is creating the mux-swapper with m.If(self.chunk_sizes[i]): - # swap path + # the mux swap path for j in range(self.width): # TODO explain what this XOR does m.d.comb += step_o[j].eq(step_i[j ^ chunk_size]) with m.Else(): - # straight path + # the mux straight path m.d.comb += step_o.eq(step_i) + step_i = step_o # for next loop, to create the combinatorial chain # TODO comment that the last "step" is the output - m.d.comb += self.output.eq(_steps[-1]) + m.d.comb += self.output.eq(_steps[-1]) # TODO: replace with step_o + + # give access to the steps list for testing purposes + self._steps = _steps + return m -- 2.30.2