From 0177d3ea7c482036c4879a7f4217aa693536ef2e Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 22 Apr 2019 21:54:47 +0100 Subject: [PATCH] derive LFSR from LFSRPolynomial - cut even more code --- TLB/src/LFSR2.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/TLB/src/LFSR2.py b/TLB/src/LFSR2.py index 4a44dfdf..e0c3d972 100644 --- a/TLB/src/LFSR2.py +++ b/TLB/src/LFSR2.py @@ -58,7 +58,7 @@ LFSR_POLY_23 = LFSRPolynomial([23, 18, 0]) LFSR_POLY_24 = LFSRPolynomial([24, 23, 22, 17, 0]) -class LFSR: +class LFSR(LFSRPolynomial): """ implements a Linear Feedback Shift Register """ def __init__(self, polynomial): @@ -76,14 +76,11 @@ class LFSR: LFSRPolynomial is derived from set() it's ok: LFSRPolynomial(LFSRPolynomial(p)) == LFSRPolynomial(p) """ - self.polynomial = LFSRPolynomial(polynomial) + LFSRPolynomial.__init__(self, polynomial) + self.width = self.max_exponent self.state = Signal(self.width, reset=1) self.enable = Signal(reset=1) - @property - def width(self): - return self.polynomial.max_exponent - def elaborate(self, platform): m = Module() # do absolutely nothing if the polynomial is empty (always has a zero) @@ -92,7 +89,7 @@ class LFSR: # create XOR-bunch, select bits from state based on exponent feedback = Const(0) # doesn't do any harm starting from 0b0 (xor chain) - for exponent in self.polynomial: + for exponent in self: if exponent > 0: # don't have to skip, saves CPU cycles though feedback ^= self.state[exponent - 1] -- 2.30.2