Skip to content

Commit

Permalink
Merge pull request enjoy-digital#13 from felixheld/crc_pythonize
Browse files Browse the repository at this point in the history
pythonize CRC calculation
  • Loading branch information
enjoy-digital authored Feb 22, 2018
2 parents 8fc7161 + 9dcc7bc commit 4e08d6e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions liteeth/core/mac/crc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def __init__(self, data_width, width, polynom):

def _optimize_eq(l):
"""
Replace even numbers of XORs in the equation
with an equivalent XOR
remove an even numbers of XORs with the same bit
replace an odd number of XORs with a single XOR
"""
d = OrderedDict()
for e in l:
Expand All @@ -55,12 +55,13 @@ def _optimize_eq(l):
r.append(key)
return r

# compute and optimize 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)]
for i in range(data_width):
feedback = curval.pop() + [("din", i)]
for j in range(width-1):
if (polynom & (1<<(j+1))):
if j+1 in taps:
curval[j] += feedback
curval[j] = _optimize_eq(curval[j])
curval.insert(0, feedback)
Expand Down

0 comments on commit 4e08d6e

Please sign in to comment.