Merge pull request #13 from felixheld/crc_pythonize
pythonize CRC calculation
This commit is contained in:
commit
4e08d6e9f9
|
@ -40,8 +40,8 @@ class LiteEthMACCRCEngine(Module):
|
||||||
|
|
||||||
def _optimize_eq(l):
|
def _optimize_eq(l):
|
||||||
"""
|
"""
|
||||||
Replace even numbers of XORs in the equation
|
remove an even numbers of XORs with the same bit
|
||||||
with an equivalent XOR
|
replace an odd number of XORs with a single XOR
|
||||||
"""
|
"""
|
||||||
d = OrderedDict()
|
d = OrderedDict()
|
||||||
for e in l:
|
for e in l:
|
||||||
|
@ -55,12 +55,13 @@ class LiteEthMACCRCEngine(Module):
|
||||||
r.append(key)
|
r.append(key)
|
||||||
return r
|
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)]
|
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)
|
||||||
|
|
Loading…
Reference in New Issue