S3.12.1 Single Error Correct, Double Error Detect

HardImplement60 minIcarus Verilog · serverReview the topic

Protect a word of 32 bits with 7 check bits, so that one flipped bit is repaired and two flipped bits are reported.

Hardware context: A memory of four words, each 8 data bits with one even-parity bit beside them, and an error injector, as test code. Parity protection of caches and other memories that hold copies

The SRAM of a chip stores 39 bits for every word of 32. On a write, an encoder works out the 39 bits. On a read, a decoder takes the 39 bits back. Any of them may have flipped since the write: data bits and check bits alike.

Write both halves as one block of logic with no clock. The bench stores what your encoder gives, flips bits, and hands the result to your decoder.

Signals in the Timeline

SignalWidthRole
trial10input of each check
Full specification
What the decoder must say
Bits that flippeddec_datacorrecteduncorrectable
nonethe data that was encoded00
exactly one, anywhere in the 39the data that was encoded10
exactly two, anywhere in the 39anything01

Any code that meets this table is accepted. The code of the lesson, made longer, is one: position 0 for the overall parity, check bits at positions 1, 2, 4, 8, 16 and 32, and the 32 data bits in the other positions up to 38.

How to read a result: for one data word, the bench tries no flip, each of the 39 single flips, and pairs of flips. "clean_right" is 1 when the first try was right. The next two fields count the single flips and the pairs that were handled as the table says. "wrong" counts every try that was not.

Examples

Example 1

All Zeros
Input
data 00000000: stored with no flip, with each one of the 39 bits flipped, and with 200 pairs of bits flipped
Output
clean_right = 1, single_flips_corrected = 39, pairs_detected = 200, wrong = 0

The word of all zeros. With no flip the data comes back and both flags are 0. Each of the 39 single flips is corrected. Each of the 200 pairs that are tried is reported as uncorrectable.

Example 2

All Ones
Input
data ffffffff: stored with no flip, with each one of the 39 bits flipped, and with 200 pairs of bits flipped
Output
clean_right = 1, single_flips_corrected = 39, pairs_detected = 200, wrong = 0

The word of all ones. The counts are the same: a code must work for every data word.

Example 3

A Mixed Word
Input
data 12345678: stored with no flip, with each one of the 39 bits flipped, and with 200 pairs of bits flipped
Output
clean_right = 1, single_flips_corrected = 39, pairs_detected = 200, wrong = 0

A mixed word. A flip of a check bit counts as an error too: corrected is 1, and the data is unchanged.

Constraints and Contract

  • enc_code depends only on enc_data. The decoder outputs depend only on dec_code.
  • While the decoder works, the bench puts other values on enc_data. A decoder cannot use it.
  • The table holds for every data word, and for every bit and every pair of bits of the 39.
  • Three or more flips are not tried.
  • The bench waits 1 ns after it changes an input.

Hints

Hint 1

How many check bits does a Hamming code need for 32 data bits? Count the positions that are powers of two.

Hint 2

Write the encoder so that each check bit covers the positions whose number has one certain bit at 1.

Hint 3

In the decoder, two questions settle everything: is the syndrome 0, and is the overall parity odd?

What the grader checks: Sixteen data words: all zeros, all ones, single ones, a single zero, patterns and random words. For each: no flip, a flip of every one of the 39 bits, and pairs of flips. One word gets all 741 pairs, and the others a thinner set. The decoder runs while the encoder input holds other data. Three or more flips are not tried.

16 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 3 problems on this path

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

All Zeros

Input
data 00000000: stored with no flip, with each one of the 39 bits flipped, and with 200 pairs of bits flipped
Expected output
clean_right = 1, single_flips_corrected = 39, pairs_detected = 200, wrong = 0

The word of all zeros. With no flip the data comes back and both flags are 0. Each of the 39 single flips is corrected. Each of the 200 pairs that are tried is reported as uncorrectable.

Run samples executes all 3 public checks. Check all tests runs 16 checks on the server.

Icarus Verilog · server