From 8db8263f3b0f12fe03d7a88e87eb1dfaccda6d43 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 22 Apr 2019 13:34:53 +0100 Subject: [PATCH] use a set not a list, can remove an extra line also, spotted that width will always be 1 or greater --- TLB/src/LFSR2.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 -- 2.30.2