mac/crc.py: make crc calculation more pythonic

This commit is contained in:
Felix Held 2018-02-21 23:11:16 +01:00
parent 2ceaa74caf
commit 9dcc7bc65e
1 changed files with 2 additions and 1 deletions

View File

@ -56,11 +56,12 @@ class LiteEthMACCRCEngine(Module):
return r return r
# compute and optimize the parallel implementation of the CRC's LFSR # compute and optimize the parallel implementation of the CRC's LFSR
taps = [x for x in range(width) if (1 << x) & polynom]
curval = [[("state", i)] for i in range(width)] curval = [[("state", i)] for i in range(width)]
for i in range(data_width): for i in range(data_width):
feedback = curval.pop() + [("din", i)] feedback = curval.pop() + [("din", i)]
for j in range(width-1): for j in range(width-1):
if (polynom & (1<<(j+1))): if j+1 in taps:
curval[j] += feedback curval[j] += feedback
curval[j] = _optimize_eq(curval[j]) curval[j] = _optimize_eq(curval[j])
curval.insert(0, feedback) curval.insert(0, feedback)