clash-lang / clash-compiler

Haskell to VHDL/Verilog/SystemVerilog compiler
https://clash-lang.org/
Other
1.43k stars 151 forks source link

Add 8b/10b encoder and decoder to `clash-cores` #2738

Closed jvnknvlgl closed 2 months ago

jvnknvlgl commented 3 months ago

Add 8b/10b encoding and decoding support to clash-cores. This is based on a lookup table which is adapted from the lookup table from LibSV.

Still TODO:

rowanG077 commented 3 months ago

For an algorithm to calculate these values look at litex 8b10b encoder/decoder: https://github.com/enjoy-digital/litex/blob/master/litex/soc/cores/code_8b10b.py

I have no clue whether or even how it works but I do know it's used in liteeth for sgmii. It seems to use some smaller tables(?? maybe not, it just looks like that from the code) then this implementation. I'm not suggesting to rewrite it like liteeth. Just a datapoint if someone find this back latter wondering if maybe we could make the table a bit more clear.

DigitalBrains1 commented 3 months ago

Since 8b10b is the concatenation of a 5b/6b and a 3b/4b encoding, it should be possible to do it with smaller tables. Unless of course there is a snag I am unaware of (such as the possibility of multiple concrete encodings being referred to as 8b10b and me talking about the wrong one).

jvnknvlgl commented 3 months ago

It seems to use some smaller tables(?? maybe not, it just looks like that from the code) then this implementation.

It splits the 8b/10b encoder into a 3b/4b encoder and a 5b/6b encoder (8b/10b is essentially a concatenation of these two schemes), which makes for the smaller hardcoded tables. Combining this leads to a table with 8 * 32 = 256 entries. The table I use adds the new running disparity and an indicator for control words to that, which gives 10 bits of data (and thus 1024 entries).