Skip to content

Commit 6bb2500

Browse files
committed
xls:modules:rle: Add description for Multisymbol RLE
Signed-off-by: Maciej Dudek <[email protected]>
1 parent 5a7ead3 commit 6bb2500

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

xls/modules/rle/rle_enc_adv.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Multisymbol Run-length Encoder
2+
3+
The encoder uses Run Length Encoding (RLE) to compress the input stream of
4+
repeating symbols to the output stream that contains the symbols and
5+
the number of its consecutive occurrences in the input stream.
6+
7+
Overall, we can break down the data processing into four stages: reduction, alignment, compression, and output generation. The division of responsibility allowed the specialized blocks to efficiently process data and made it possible test each functionality separately.
8+
9+
The first block is responsible for taking the input and reducing it to pairs of symbols and the number of its occurrences, as in the [basic RLE implementation](https://github.com/google/xls/pull/974). The second element of the encoder shifts the previously emitted pairs and adjusts them for further processing. Both of these elements have an empty state. The next block takes the prepared data and combines it with the information about previously processed symbols. The last element is responsible for adjusting the width of the output data to the receiver interface.
10+
11+
12+
Input width is defined using the `INPUT_WIDTH` parameter and output width is defined with the `OUTPUT_WIDTH` parameter.
13+
Both the input and the output channels use additional `last` flag
14+
that indicates whether the packet ends the transmission. After sending
15+
the last packet the encoder dumps all the data to the output stream.
16+
17+
## Encoder processing pipeline detailed breakdown.
18+
19+
### Initial conditions
20+
- input width is 4 symbols wide,
21+
- output width is 2 pairs wide,
22+
- symbol counter is 2 bits wide.
23+
24+
### Process
25+
1. Reduce step - this process takes incoming symbols and symbol_valid
26+
and reduces them into symbol count pairs. This step is stateless.
27+
28+
Example:
29+
30+
|||
31+
|-----|-------|
32+
|input|output |
33+
|[(A, True), (A, True), (A, True), (A, True)]|[.., .., (A, 3), (A, 1)]|
34+
|input|output |
35+
|[(A, True), (A, True), (A, False), (A, True)]|[.., .., .., (A, 3)]|
36+
|input|output |
37+
|[(A, True), (B, True), (C, True), (D, True)]|[(A, 1), (B, 1), (C, 1), (D, 1)]|
38+
39+
2. Realign step - this process moves pairs emitted from the reduce step
40+
so that they are aligned to the left, it also calculates propagation
41+
distance for the first pair.
42+
43+
Example:
44+
45+
||||
46+
|-----|-------|--------------------|
47+
|input|output |propagation distance|
48+
|[.., (A, 2), .., (B, 2)]|[(A, 2), (B, 2), .., ..]| 0|
49+
|input|output |propagation distance|
50+
|[.., .., (A, 3), (A, 1)]|[(A, 3), (A, 1), .., ..]| 1|
51+
52+
3. Core step - this step is stateful. It takes align pairs from
53+
the realign step, and combines them with its state to create multiple
54+
symbol/count pairs output. State is represented by following tuple
55+
`<symbol, count, last>`. It contains symbol and count from last pair
56+
received from the realign step, or current sum of repeating symbol spanning
57+
multiple input widths.
58+
59+
Example:
60+
61+
|||||
62+
|------|-----|-------|----------|
63+
|state |input|output |next state|
64+
|(A, 2)| [(A, 2), (B, 2), .., ..]|[(A, 3), (A, 1), .., ..]| (B, 2)|
65+
|state |input|output |next state|
66+
|(A, 1)| [(A, 1), (B, 2), .., ..]|[(A, 2), .., .., ..]| (B, 2)|
67+
|state |input|output |next state|
68+
|(A, 1)| [(A, 1), .., .., ..]|[.., .., .., ..]| (A, 2)|
69+
70+
4. Adjust Width step - this step takes output from the core step.
71+
If output can handle more or equal number of pairs as
72+
input number of symbols. This step does nothing.
73+
If the output is narrower than the input,
74+
this step will serialize symbol counter pairs.
75+
76+
Example:
77+
78+
|||||
79+
|-----|-----|-------|-----------|
80+
|state|input|output | next state|
81+
|[]|[(A, 3), (A, 2), .., ..]|[(A, 3), (A, 2)]|[]|
82+
|state|input|output | next state|
83+
|[]|[(A, 1), (B, 1), (C, 1), (D, 1)]|[(A, 1), (B, 1)]|[(C, 1), (D, 1)]|
84+
|state|input|output | next state|
85+
|[(C, 1), (D, 1)]|ignored|[(C, 1), (D, 1)]|[]|

0 commit comments

Comments
 (0)