Luke Kenneth Casson Leighton
lkcl at lkcl.net
Mon Apr 22 13:27:05 BST 2019
On Mon, Apr 22, 2019 at 8:56 AM Jacob Lifshay <programmerjake at gmail.com> wrote:
> Daniel, just in case you didn't see the email from the bug report, I
> ended up writing a LFSR implementation at the same time you did:
ha, whoops :) that was quick, both of you, excellently-fast work!
hmmm, how can a clash be avoided in the future?
ok i did a rework of LFSR2.py: daniel, i like what you wrote (short!)
however jacob's code is general-purpose, and the unit test's really
jacob there's a lot to like about what you wrote (extensively
checking the inputs to LFSRPolynomial for example): although it wasn't
the intention of asking you if you could write an LFSR to do an
extensive review, the original intention was for you to feel like
you're part of the team and actively engaging with me and daniel.
so i thought it would be useful to morph it to be more along the
lines of python, to show you (and daniel) some of the "tricks" of
python, and in particular, to be much more direct. remove the
abstract class (derive from set not abstract Set), remove the typing
(moved to a .pyi file), remove properties that aren't needed, and so
also there's a trick with Cat() that means assigning to the LSB isn't needed....
... the thing is, there were *so many* things (10 commits in one
hour!!) i thought it best done as a video:
hope it proves useful.
oh. just reviewing it now: i missed out that newstate is a *python*
variable, that is then assigned to state. it's still 2 lines, however
it's a lot clearer:
pythonvariable = foo + foo + foo + foo + 5
m.d.sync += foo.eq(pythonvariable)
is a lot less messy than:
m.d.sync += foo.eq(
foo + foo + foo + foo + foo + 5)
the only thing to watch out for is *not* to use the python variable
multiple times. the pythonvariable contains nmigen *code fragments*,
consequently using it more than once will result in DUPLICATION of the
gates it represents.
both daniel and i got caught out by that one, early on.
More information about the libre-riscv-dev