From: Luke Kenneth Casson Leighton Date: Mon, 22 Apr 2019 12:34:53 +0000 (+0100) Subject: use a set not a list, can remove an extra line X-Git-Tag: div_pipeline~2163 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8db8263f3b0f12fe03d7a88e87eb1dfaccda6d43;p=soc.git use a set not a list, can remove an extra line also, spotted that width will always be 1 or greater --- diff --git a/TLB/src/LFSR2.py b/TLB/src/LFSR2.py index 1bddc1a8..62ee8f5c 100644 --- a/TLB/src/LFSR2.py +++ b/TLB/src/LFSR2.py @@ -9,15 +9,14 @@ class LFSRPolynomial(set): """ def __init__(self, exponents=()): self.max_exponent = 0 - elements = [0] # 0 is always required + elements = {0} # 0 is always required for e in exponents: if not isinstance(e, int): raise TypeError("exponent %s must be an integer" % repr(e)) if e < 0: raise ValueError("exponent %d must not be negative" % e) self.max_exponent = max(e, self.max_exponent) - if e != 0: # skip any zeros - elements.append(e) + elements.add(e) # uniquifies additions (it's a set!) set.__init__(self, elements) @@ -90,8 +89,8 @@ class LFSR: def elaborate(self, platform): m = Module() - # do absolutely nothing if the polynomial is empty - if self.width == 0: + # do absolutely nothing if the polynomial is empty (always has a zero) + if self.width <= 1: return m # create XOR-bunch, select bits from state based on exponent