A PAM4 lane sends two bits on one of four levels. Write the Gray map in both directions, then the precoder and its decoder.
Hardware context: An Ethernet MAC and physical coding sublayer: frame builder and checker, reconciliation sublayer and block encoder. Build, check and pace Ethernet frames, and code them for the physical layer as IEEE 802.3 specifies.
Four small functions work on one PAM4 lane. Each call handles 64 symbols.
gray_map turns pairs of bits into levels (120.5.7.1). gray_unmap turns levels back into pairs.
precode is the 1/(1+D) mod 4 precoder of the transmitter (135.5.7.2). decode undoes it at the receiver.
Both take en. With en = 0 they hand their input on unchanged.
Both take prev, the symbol before the first one of the vector. So a long stream can go through in pieces.
The standard gives test data: the first symbols of four training patterns (Table 136-8). Six tests use it.
The lesson states the rules as tables. Its readable model is a bench channel: it holds none of these functions.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
test_number | 8 | input of each check |
Full specification
function automatic [127:0] gray_map(input [127:0] bits);
function automatic [127:0] gray_unmap(input [127:0] sym);
function automatic [127:0] precode(input [127:0] g, input [1:0] prev, input bit en);
function automatic [127:0] decode(input [127:0] p, input [1:0] prev, input bit en);
| Item | Rule |
|---|---|
| Bits | a course choice of layout: bits[i] is the i-th bit of the lane. Bit 0 arrives first |
| Symbols | a course choice of layout: symbol j is bits 2j and 2j + 1 of a symbol vector, a level 0 to 3. Symbol 0 is sent first |
| Pair | pair j is {A, B}. A is bits[2j], the bit that arrives first. B is bits[2j + 1] |
gray_map | {0, 0} gives level 0, {0, 1} gives 1, {1, 1} gives 2 and {1, 0} gives 3 (120.5.7.1) |
gray_unmap | the same table read the other way. A goes back to bits[2j] |
precode | P(j) = (G(j) − P(j − 1)) mod 4 (135.5.7.2). G is the input g, P the result |
decode | G(j) = (P(j) + P(j − 1)) mod 4. P is the input p: what the receiver decided |
prev | a course choice: P(j − 1) for j = 0. The standard fixes it only for a training pattern, where it is 0 (136.8.11.1.3) |
en = 0 | the result is the input: P(j) = G(j) and G(j) = P(j). prev is not used |
| mod 4 | the result is always 0 to 3. 1 − 3 gives 2, and 3 + 2 gives 1 |
Random tests compare each function with a private model on whole vectors.
Examples
Example 1
Map the Four Pairs- Input
the pairs 00, 01, 11, 10 in sending order
- Output
symbol_0 = 0, symbol_1 = 1, symbol_2 = 2, symbol_3 = 3, symbol_4 = 0, symbol_5 = 1, symbol_6 = 2, symbol_7 = 3, xor_of_all_31_bit_slices = 0x19999997, xor_of_all_19_bit_slices = 0x62727
They give the levels 0, 1, 2, 3. The pair 11 is level 2, not 3: that is the Gray code.
Example 2
Precode a Ramp- Input
the levels 0, 1, 2, 3 again and again; `prev` = 0
- Output
symbol_0 = 0, symbol_1 = 1, symbol_2 = 1, symbol_3 = 2, symbol_4 = 2, symbol_5 = 3, symbol_6 = 3, symbol_7 = 0, xor_of_all_31_bit_slices = 0x4d4d4d4e, xor_of_all_19_bit_slices = 0x386d
P(0) = 0 − 0 = 0. P(1) = 1 − 0 = 1. P(2) = 2 − 1 = 1. P(3) = 3 − 1 = 2. P(4) = 0 − 2 wraps to 2.
Example 3
Decode the First Training Pattern- Input
the precoded levels 1, 3, 0, 1, 2, 0, 0, 2 of Table 136-8; `prev` = 0
- Output
symbol_0 = 1, symbol_1 = 0, symbol_2 = 3, symbol_3 = 1, symbol_4 = 3, symbol_5 = 2, symbol_6 = 0, symbol_7 = 2, xor_of_all_31_bit_slices = 0x7b400aad, xor_of_all_19_bit_slices = 0x51460
G(0) = 1 + 0 = 1. G(1) = 3 + 1 wraps to 0. G(2) = 0 + 3 = 3. The table's PAM4 column starts 1, 0, 3.
Constraints and Contract
- Keep the four names and their arguments.
- A call must not depend on the calls before it.
- You may add helper functions.
- Do not call a variable
before: it is a reserved keyword of SystemVerilog (IEEE 1800 Annex B). - Off limits: the names
ref_p,rng,tb,rootand the modules of the bench. - The fixture's own names are off limits too. They begin with
fx_.
Hints
Hint 1
Start with gray_map: a case with four lines inside a loop of 64.
Hint 2
In precode, keep the last precoded symbol in a variable. Start it at prev.
Hint 3
A two-bit variable wraps at 4 by itself. With an int, add 4 before the % 4.
Hint 4
The decoder adds two received symbols. It never uses its own result.
Hint 5
Declare your variables at the top of a function, not inside a loop.
What the grader checks: Six tests use Table 136-8 of IEEE Std 802.3-2022, the first symbols of the training patterns. A JavaScript model gives the expected values. It must reproduce all four rows of that table and the 46 symbols of 120.5.11.2.1 when the problem is built. Eleven more tests are fixed, and four compare random vectors with a private model, bit for bit. The vector layouts, 64 symbols a call and the prev argument are course choices. The PRBS13 generator, the four PAM4 voltages, the enable registers and link training are not graded.
21 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 1 steps and the final capstone