derive LFSR from LFSRPolynomial - cut even more code
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 22 Apr 2019 20:54:47 +0000 (21:54 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 22 Apr 2019 20:54:47 +0000 (21:54 +0100)
TLB/src/LFSR2.py

index 4a44dfdf0905e9528bedbd28f3a91479b69ed79b..e0c3d972fa36975e4723675aba9bbe8760ac8e8e 100644 (file)
@@ -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]