[libre-riscv-dev] [Bug 316] bperm TODO
bugzilla-daemon at libre-soc.org
bugzilla-daemon at libre-soc.org
Sat May 16 05:35:10 BST 2020
https://bugs.libre-soc.org/show_bug.cgi?id=316
--- Comment #13 from Luke Kenneth Casson Leighton <lkcl at lkcl.net> ---
ok. right. re-run the generate -t ilang, and yosys show top.
then trace "rs", note how there are *two* copies of 8-bit chunks of rs?
one that goes into the "lt" (less-than) comparison, and a *second* copy
that goes into the the big "group" (this is a massive multiplexer btw)
that's 2x copies of 8 8-bit chunks.
so let's trace it back.
what thing or things - related to rs - have an 8-bit width?
well, that will be index, won't it?
index = self.rs[8 * i:8 * i + 8]
now, look where index is used.
first time:
with m.If(index < 64):
that's where the lt (less-than) comes in (times 8)
second time:
(rb64[index])
this is really important to note the difference between a *python* variable
and a nmigen Abstract Syntax Tree code-fragment.
you have created - with the "index = self.rs[blah blah]" a *python* variable
assignment from a *nmigen AST*.
therefore, whereever you use that python variable it INSERTS A COPY OF THAT
NMIGEN AST... into more nmigen AST.
now, in this particular case, that's fine (it's not a pretty graph) but in
cases where you did something like this:
index = Cat(rs[blah], 5) * i + rb[i] * 3, rs[i] & rb[i])
or anything hugely and massively complex, that would ALSO GET INSERTED TWICE
and you would end up with a huge duplication of gate logic as a result, which
yosys would be very unlikely to spot and optimise away.
the solution - therefore - the best practice - is never to assign anything
other
than the most basic of nmigen objects - Signals, Consts, Records etc. - to a
python variable
OR
to actually create a Signal into which that nmigen AST fragment is assigned...
*and then use that signal*.
in this case that would be:
index = ...
idx = Signal(8, name="idx%d" % i, reset_less=True)
m.d.comb += idx.eq(index)
and then
m.If(idx < 64)
and also
rb64[idx]
see what difference that makes to the graphviz, ok?
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the libre-riscv-dev
mailing list