TDEB Top Bar

Trending
Semiconductor Industry News — The Digital Electronics Blog
Follow Us

TDEB Masthead

The Semiconductor Hub

Semiconductors.  Chips and Systems.  Innovation.

Indexed by leading Search Engines, AI and referenced by Engineers worldwide 500+ Articles 10M+ Pageviews 30+ Reports 50+ Citations

ECC-Protected FIFO Design: SECDED Encoding and Decoding at Full Throughput (FIFO Series, Part 27)

The Semiconductor Hub
by
0
Share Facebook X LinkedIn WhatsApp Email
Hand-drawn cover card for FIFO Series Part 27, ECC-Protected FIFO, with a sketch of entries moving from push to pop.

A FIFO that holds data for only a few cycles still holds it in storage that can be upset. A particle strike, a marginal SRAM cell at low voltage, or a weak flop at a corner can flip a bit between the push and the pop. In a chip that must not return wrong data silently, such as a server memory path, an automotive controller or a network switch, every FIFO on the data path is part of the error budget.

This part adds SECDED protection to a FIFO: single-error correction and double-error detection, a Hamming code with one extra parity bit, the scheme widely used for server memory. The goal is to do it at full throughput, one push and one pop every cycle, and to keep the encoder and decoder off the paths that already set the FIFO's clock rate.

Key takeaways

  • Encode on the way in and decode on the way out. The storage holds codewords, so 32 data bits become 39 stored bits and 64 become 72.
  • The decoder is three XOR trees and a small decoder: the syndrome, an overall parity bit, and a one-hot correction. A single flipped bit is corrected, two flipped bits are flagged.
  • Put the decode after the registered read, or in its own pipeline stage. The encoder usually fits in the write cycle.
  • Three or more flipped bits are always flagged by this decoder, but can be miscorrected and reported as a single error. That is the limit of SECDED, not a bug.
  • Verify with an error injection port, an exhaustive sweep of every single and double error, and a scoreboard that knows how many bits were flipped in each entry.

In this part

What problem it solves

A parity bit per entry detects one flipped bit but cannot fix it, so the system must retry or report a fatal error. Deep in a data path, with no copy upstream, a retry may not be possible.

SECDED fixes the common case and flags the rare one. A single upset, the most likely event in a small structure, is corrected in line and counted. A double upset is reported, so the data can be poisoned instead of passed on silently. The cost is a few bits per entry and XOR logic at each end.

The interface

Hand-drawn block diagram of an ECC-protected FIFO: wdata passes through a SECDED encoder into a storage array of 39-bit codewords, and the read side passes the registered codeword through a syndrome decoder and correction to rdata, with sbe and dbe flags.

The data interface is unchanged from Part 1: push, wdata and full, pop, rdata and empty. Three outputs and one test input are added:

  • sbe: the data on rdata had one flipped bit, which has been corrected.
  • dbe: the data on rdata is uncorrectable. Treat it as poisoned.
  • sbe_cnt and dbe_seen: a saturating count of corrected errors and a sticky uncorrectable flag, for software or a safety monitor to read.
  • inj_mask: an error injection mask XORed into the codeword on the write path. It is tied to zero in mission mode and driven by tests and by built-in self-test.

The flags arrive with the data, one cycle after the pop, qualified by a read-valid bit.

Micro-architecture: the SECDED code

Number the codeword bits from 1. The positions that are powers of two, 1, 2, 4, 8 and so on, hold check bits. Every other position holds a data bit, in order. Check bit p is the XOR of every position whose index has bit p set. Bit 0 holds one more parity bit over the whole word.

Hand-drawn layout of a SECDED codeword: check bits at positions 1, 2, 4, 8, 16 and 32, data bits in the other positions, overall parity at position 0, and a decision table for syndrome and overall parity.

On the read side, XOR together the indices of every bit that is set. For a clean codeword this syndrome is zero. If exactly one bit flipped, the syndrome is the index of that bit, and the overall parity is odd. That gives a four-way decision:

  • Syndrome zero, parity even. No error.
  • Parity odd, syndrome points inside the word. One error. Flip the bit the syndrome names. A zero syndrome with odd parity means the overall parity bit itself flipped.
  • Parity even, syndrome non-zero. Two errors. Flag dbe.
  • Parity odd, syndrome outside the word. An odd number of errors, at least three. Flag dbe. This happens when the code is shortened, as it is for 32 data bits: six check bits can name 63 positions, but only 38 exist.

The number of check bits is the smallest P with 2 to the power P at least W + P + 1. For W of 4 or more, $clog2(W + $clog2(W) + 1) gives it, which the model checks for every width from 4 to 1024.

RTL sketch

Encoder and decoder as loops that synthesis unrolls into XOR trees, around the flip-flop FIFO from Part 1:

module ecc_fifo #(
  parameter int W     = 32,
  parameter int DEPTH = 16,                   // power of two
  localparam int AW   = $clog2(DEPTH),
  localparam int P    = $clog2(W + $clog2(W) + 1),
  localparam int CW   = W + P + 1             // 39 for W = 32
) (
  input  logic          clk, rst_n,
  input  logic          push,
  input  logic [W-1:0]  wdata,
  input  logic [CW-1:0] inj_mask,             // tie to 0 in mission mode
  output logic          full,
  input  logic          pop,
  output logic [W-1:0]  rdata,
  output logic          sbe, dbe,             // valid with rdata
  output logic [7:0]    sbe_cnt,
  output logic          dbe_seen,
  output logic          empty
);
  function automatic logic [CW-1:0] enc(input logic [W-1:0] d);
    int k = 0;
    enc = '0;
    for (int pos = 1; pos < CW; pos++)
      if ((pos & (pos - 1)) != 0) begin enc[pos] = d[k]; k++; end
    for (int p = 0; p < P; p++)
      for (int pos = 1; pos < CW; pos++)
        if (((pos >> p) & 1) && ((pos & (pos - 1)) != 0))
          enc[1 << p] ^= enc[pos];
    enc[0] = ^enc[CW-1:1];
  endfunction

  logic [CW-1:0] mem [DEPTH];
  logic [AW:0]   wptr, rptr;
  logic [CW-1:0] rcw;                         // registered codeword
  logic          rvalid;

  assign empty = (wptr == rptr);
  assign full  = (wptr[AW-1:0] == rptr[AW-1:0]) && (wptr[AW] != rptr[AW]);
  wire do_pop  = pop  && !empty;
  wire do_push = push && (!full || do_pop);

  // decode the registered codeword
  logic [P-1:0]  syn;
  logic          par;
  logic [CW-1:0] cc;
  always_comb begin
    int k;
    k   = 0;
    syn = '0;
    for (int pos = 1; pos < CW; pos++)
      if (rcw[pos]) syn ^= P'(pos);
    par = ^rcw;
    cc  = rcw;
    if (par && syn < CW) cc[syn] = ~cc[syn];
    for (int pos = 1; pos < CW; pos++)
      if ((pos & (pos - 1)) != 0) begin rdata[k] = cc[pos]; k++; end
    sbe = rvalid && par && (syn < CW);
    dbe = rvalid && (par ? (syn >= CW) : (syn != 0));
  end

  always_ff @(posedge clk or negedge rst_n)
    if (!rst_n) begin
      wptr <= '0;  rptr <= '0;  rvalid <= 1'b0;
      sbe_cnt <= '0;  dbe_seen <= 1'b0;
    end else begin
      if (do_push) wptr <= wptr + 1'b1;
      if (do_pop)  rptr <= rptr + 1'b1;
      rvalid <= do_pop;
      if (sbe && sbe_cnt != 8'hFF) sbe_cnt <= sbe_cnt + 1'b1;
      if (dbe) dbe_seen <= 1'b1;
    end

  always_ff @(posedge clk) begin
    if (do_push) mem[wptr[AW-1:0]] <= enc(wdata) ^ inj_mask;
    if (do_pop)  rcw <= mem[rptr[AW-1:0]];
  end
endmodule

Note that rdata holds its value between pops, as in Part 1, because rcw only loads on a pop. The flags drop after one cycle because rvalid does. The sketch was checked with a Python model that mirrors it line for line: every single and double error at widths 8, 32 and 64, and 600,000 random FIFO cycles with 0 to 3 bits injected per entry, against a reference queue. Single errors were always corrected, double errors always flagged, and no three-bit error was ever silent.

Corner cases

  • Error in a check bit. The data is already correct. The decoder still flips the check bit and reports sbe, which is right: the stored word did have an error, and the count should reflect it.
  • Error in the overall parity bit. Syndrome zero, parity odd. Report a single error; the data needs no change.
  • Three or more errors. With odd parity and a syndrome inside the word, the decoder flips a wrong bit and reports sbe. Nothing in a SECDED code can tell this from a true single error. If the system cannot tolerate that risk, use a stronger code or add a separate check such as a CRC on the packet.
  • Uninitialized storage. The array has no reset, so an entry that was never written decodes to garbage. That is harmless as long as nothing reads it, and the empty flag guarantees that. Do not run a decoder on idle reads, or dbe will fire on power-up junk; the rvalid qualifier handles it.
  • Pointers and flags. ECC on the data does nothing for an upset in a pointer register. A flipped pointer bit reorders or loses data with no flag. Safety designs protect pointers with parity or duplication and compare, which costs little because pointers are small.

Timing, area and power

Hand-drawn pipeline options for an ECC-protected FIFO: decoding in the same cycle as the registered read, or adding a decode stage that costs one cycle of latency but keeps full throughput.
  • Encoder. Each check bit is an XOR of roughly half the data bits, so a tree of depth about log2 of W. It sits between wdata and the array. If wdata arrives late, register it first and encode in the next cycle, at the cost of one cycle of latency on the push side.
  • Decoder. Syndrome trees in parallel with the overall parity tree, then a P-to-CW one-hot decode, then one XOR per data bit. That is longer than the encoder. Doing it after the read register is usually fine for a FIFO; at high clock rates add a register after the decoder. Throughput stays at one entry per cycle either way; only latency grows.
  • Area. 7 extra bits on 32 is about 22 percent more storage, 8 on 64 is 12.5 percent. Wider words are cheaper per bit, which is one reason buses protect 64-bit or wider words.
  • Power. Load the decoder input register only on do_pop, as the sketch does, so idle cycles do not toggle the XOR trees.
  • Bypass paths. A first-word fall-through FIFO with a bypass from wdata to rdata skips the storage, so the bypass data needs no decode. Mux after the decoder, not before, so the bypass path is not slowed down.

Verification checklist

  • An exhaustive unit test of the codec: for many random data words, every single-bit flip must correct with sbe, and every pair must flag dbe with no sbe.
  • A scoreboard that records, for each push, the data and how many bits were injected. On the pop, zero flips must give clean data, one must give corrected data and sbe, two must give dbe, and three or more must raise at least one flag.
  • Assertions:
    a_flags_excl: assert property (@(posedge clk) disable iff (!rst_n)
                    !(sbe && dbe));
    a_flags_qual: assert property (@(posedge clk) disable iff (!rst_n)
                    (sbe || dbe) |-> rvalid);
    a_no_inj:     assert property (@(posedge clk) disable iff (!rst_n)
                    mission_mode |-> inj_mask == '0);
  • Coverage: an error in every bit position, including each check bit and the overall parity bit; double errors that hit two check bits; errors at the full boundary with push and pop in the same cycle; and the counter saturating.
  • Formal suits the codec alone: prove single correction and double detection for all data.

Interview questions

1. How many check bits does SECDED need for 64 data bits, and why?

A strong answer derives seven Hamming bits from 2 to the power P at least W + P + 1, adds one overall parity bit for double detection, and arrives at 72 bits.

2. Walk through the decoder's decision table.

A strong answer covers all four cases of syndrome and overall parity, including the zero syndrome with odd parity and the syndrome that points outside a shortened word.

3. Where do you put the decoder in a FIFO running at a high clock rate?

A strong answer places it after the registered read and adds a pipeline stage if needed, stating that throughput is unchanged and only latency grows.

4. What does SECDED not protect you from in this FIFO?

A strong answer names miscorrected triple errors and upsets in the pointers, and proposes parity or duplication on the pointers.

5. How do you verify ECC when the simulator never flips bits on its own?

A strong answer describes an injection mask on the write path, a scoreboard that tracks the injected flip count, an exhaustive codec test, and formal proofs on the codec.

Where it is used in real chips

ECC-protected FIFOs sit in memory controller read and write queues, in the data buffers of PCIe and CXL controllers, in NoC routers on chips with reliability targets, and in the staging buffers of DMA engines and accelerators that move large data sets. In safety-related designs they usually come with pointer protection and an error reporting path to a central fault collector.

The rest of the series

Part 26 covered the checkpointed FIFO, which saves the write pointer at each guess and restores it on a misprediction.

Part 28 turns to power: a low-power FIFO with clock gating and bank gating that never loses data or throughput.

Share Facebook X LinkedIn WhatsApp Email

Post a Comment

0 Comments

Your comments will be moderated before it appears here.

Post a Comment (0)

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn more
Ok, Go it!