From 2ceaa74caf35097c44d296a25f58ac81e8730e9a Mon Sep 17 00:00:00 2001 From: Felix Held Date: Wed, 21 Feb 2018 21:15:51 +0100 Subject: [PATCH 1/2] clarify the comments in mac/crc.py code --- liteeth/core/mac/crc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/liteeth/core/mac/crc.py b/liteeth/core/mac/crc.py index 33ca9c9..2b56d8e 100644 --- a/liteeth/core/mac/crc.py +++ b/liteeth/core/mac/crc.py @@ -40,8 +40,8 @@ class LiteEthMACCRCEngine(Module): 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: @@ -55,7 +55,7 @@ class LiteEthMACCRCEngine(Module): r.append(key) return r - # compute and optimize CRC's LFSR + # compute and optimize the parallel implementation of the CRC's LFSR curval = [[("state", i)] for i in range(width)] for i in range(data_width): feedback = curval.pop() + [("din", i)] From 9dcc7bc65e514f6ab645aa18edb881bda4f73594 Mon Sep 17 00:00:00 2001 From: Felix Held Date: Wed, 21 Feb 2018 23:11:16 +0100 Subject: [PATCH 2/2] mac/crc.py: make crc calculation more pythonic --- liteeth/core/mac/crc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/liteeth/core/mac/crc.py b/liteeth/core/mac/crc.py index 2b56d8e..fb0e0bc 100644 --- a/liteeth/core/mac/crc.py +++ b/liteeth/core/mac/crc.py @@ -56,11 +56,12 @@ class LiteEthMACCRCEngine(Module): return r # 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)