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

Multi-Reader FIFO Design: Independent Read Pointers Over One Shared Buffer (FIFO Series, Part 29)

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

Sometimes one stream has more than one consumer. A trace stream goes both to an on-chip buffer and to an external port. A tile of activations is read by two compute units. A packet is sent to its destination and copied to a monitor. Each consumer needs every entry, in order, but they do not run in lockstep: one may stall for a while, another may run at full rate.

You could give each consumer its own FIFO and copy every push into all of them, but that multiplies the storage by the number of readers. A multi-reader FIFO keeps one copy of the data and gives each reader its own read pointer. This part covers how space is freed, how full is computed, and how readers join and leave while traffic is running.

Key takeaways

  • One write pointer, one read pointer per reader, one shared array. Each reader sees an ordinary FIFO with its own empty and rdata.
  • An entry is free only when every active reader has read it, so space is limited by the slowest reader. Full means "full for at least one reader".
  • A push at full is still safe if every reader that is full pops in the same cycle.
  • Readers that are detached must not hold space. Attach a reader by setting its pointer to the write pointer, so it sees only new data.
  • The cost is read ports. A flop array needs one read mux per reader; an SRAM needs a multi-port macro or a scheme to share one port.

In this part

What problem it solves

There are three ways to feed one stream to R consumers. Separate FIFOs cost R copies of the storage and R write ports, and each FIFO's depth is sized on its own. A broadcast scheme, which is Part 30, keeps one head entry and holds it until every consumer has taken it, so the slowest consumer stalls the others on every entry. A multi-reader FIFO sits in between: one copy of the data, and each reader moves at its own pace until the FIFO fills.

The trade-off is simple to state. The fast readers are never held back by the slow one as long as there is space. When the slow reader falls a full FIFO behind, the writer stalls, and through it, everyone else.

The interface

Hand-drawn block diagram of a multi-reader FIFO: one writer with push, wdata and full, a shared storage array, and three readers each with its own read pointer, pop, rdata and empty.

The writer has push, wdata and full. Each reader r has pop[r], rdata[r] and empty[r]. The sketch uses a show-ahead read: rdata[r] is the reader's oldest unread entry whenever empty[r] is low, and a pop moves past it. That makes each reader look like the first-word fall-through FIFO of Part 3.

Two more inputs per reader, attach[r] and detach[r], let a consumer join or leave without a reset. A detached reader is always empty and never counts toward full.

Micro-architecture

The writer's view of occupancy is the distance from the write pointer to the slowest active read pointer. Rather than finding that minimum, which needs subtractors and a comparison tree, the sketch checks each reader on its own with the wrap-bit test from Part 1. A reader is full when its pointer has the same index bits as the write pointer and a different top bit. The FIFO is full when any active reader is full.

Hand-drawn view of an eight-entry multi-reader FIFO with one write pointer and three read pointers at different positions; the slowest reader decides how much space is left.

In the picture, reader A is close behind the writer and reader C is far behind. The entries between C and B have been read by A and B but not by C, so they are still live. Only the slots behind C are free. If C stops, the writer stops after filling those slots, and A and B drain to empty and wait.

A push at the full boundary follows the same rule as in Part 1, extended to many readers. The push is accepted if every reader that is full also pops in this cycle. One full reader that does not pop blocks the push, no matter what the others do.

Attach sets the reader's pointer to the current write pointer, so it sees the push in the attach cycle and everything after. Older slots are protected only for readers that were active when the data arrived, so a reader that needs history must attach before it arrives.

RTL sketch

module mr_fifo #(
  parameter int W     = 32,
  parameter int DEPTH = 16,                  // power of two
  parameter int R     = 3,                   // readers
  localparam int AW   = $clog2(DEPTH)
) (
  input  logic         clk, rst_n,
  input  logic         push,
  input  logic [W-1:0] wdata,
  output logic         full,
  input  logic [R-1:0] pop,
  output logic [W-1:0] rdata [R],            // show-ahead
  output logic [R-1:0] empty,
  input  logic [R-1:0] attach, detach,
  output logic [R-1:0] active
);
  logic [W-1:0] mem [DEPTH];
  logic [AW:0]  wptr;
  logic [AW:0]  rptr [R];
  logic [R-1:0] full_r, do_pop;

  always_comb
    for (int r = 0; r < R; r++) begin
      empty[r]  = !active[r] || (rptr[r] == wptr);
      full_r[r] = active[r] && (rptr[r][AW-1:0] == wptr[AW-1:0])
                            && (rptr[r][AW]     != wptr[AW]);
      do_pop[r] = pop[r] && !empty[r];
      rdata[r]  = mem[rptr[r][AW-1:0]];
    end

  assign full    = |full_r;
  wire   do_push = push && ((full_r & ~do_pop) == '0);

  always_ff @(posedge clk or negedge rst_n)
    if (!rst_n) begin
      wptr   <= '0;
      active <= '0;
      for (int r = 0; r < R; r++) rptr[r] <= '0;
    end else begin
      if (do_push) wptr <= wptr + 1'b1;
      for (int r = 0; r < R; r++)
        if (attach[r]) begin
          active[r] <= 1'b1;
          rptr[r]   <= wptr;                  // sees this cycle's push onward
        end else if (detach[r]) active[r] <= 1'b0;
        else if (do_pop[r])     rptr[r]   <= rptr[r] + 1'b1;
    end

  always_ff @(posedge clk)
    if (do_push) mem[wptr[AW-1:0]] <= wdata;
endmodule

A Python model that mirrors the sketch ran 600,000 random cycles with 2 to 4 readers at depths 4 to 16, changing each reader's pop rate every 400 cycles and attaching and detaching readers at random. A reference that keeps an absolute position per reader checked every rdata, every empty flag and every count. All passed, including tens of thousands of pushes at full where all full readers popped and many more where one reader blocked the push.

Corner cases

Hand-drawn timing diagram of a two-reader FIFO of depth four: reader A pops every cycle, reader B stalls, the FIFO fills for B and the writer stops, then B pops and a push at full is accepted in the same cycle.
  • Full for one reader only. Reader B is four entries behind in a depth-four FIFO, reader A is empty. full is high, and A waits on an empty FIFO. This is the cost of shared space.
  • Push at full with a pop. Accepted when every full reader pops. In the timing diagram, B pops in cycle 7 and the writer's push in that cycle goes into the slot B just left.
  • Slowest reader detaches. Its space is released at once, since it no longer counts toward full. That is the right behavior for a consumer that has been switched off, and the wrong one if the detach was a mistake, so protect detach with a clear owner.
  • Attach while full. The new reader's pointer equals the write pointer, so it is empty and cannot block anything. Its first entry is the next push.
  • No active readers. The sketch keeps accepting pushes, and the data is simply never read. If the writer should stall instead, gate do_push on at least one active reader. Pick one and write it in the spec.
  • A consumer that never returns. A dead reader stops the writer for good. Long-lived systems add a watchdog that detaches a reader stuck at full for too long and reports it.

Timing, area and power

  • Read ports. Each reader needs a DEPTH-to-1 mux of W bits. With flops this grows with R times DEPTH times W. With SRAM, R read ports are expensive or not offered. Common alternatives: time-share one SRAM read port among readers, each with a small prefetch FIFO in front; or bank the array so readers on different banks do not conflict, using the banking ideas of Part 34.
  • Full logic. R comparators and an OR. It scales well. A level output for almost-full is harder: it needs the maximum of R pointer differences, a subtract-and-compare tree. Register it if a threshold is needed every cycle.
  • Write path. Unchanged from Part 1. The write happens once, which is the main saving over R separate FIFOs.
  • Power. The read muxes toggle when their pointers move. Gate each reader's output register on its own pop if the read is registered.
  • Sizing. Size for the largest lag between the fastest and slowest reader you want to absorb, plus the producer's burst. If one reader is always much slower, a separate FIFO for that reader may be cheaper than a deep shared one.

Verification checklist

  • A reference that keeps one absolute position per reader and one shared list of entries. Check rdata[r] whenever empty[r] is low, and check every flag every cycle.
  • Assertions:
    a_attach_idle: assert property (@(posedge clk) disable iff (!rst_n)
                     attach[r] |-> !active[r]);
    a_no_both:     assert property (@(posedge clk) disable iff (!rst_n)
                     !(attach[r] && detach[r]));
    a_space:       assert property (@(posedge clk) disable iff (!rst_n)
                     active[r] |-> (wptr - rptr[r]) <= DEPTH);
    with r from a generate loop.
  • Traffic with per-reader rates that change over time, so each reader in turn is the slowest.
  • Coverage: push at full with all full readers popping, push blocked by exactly one reader, two readers full at once, attach in a cycle with a push, detach of the slowest reader, and no active readers.

Interview questions

1. How do you compute full with three readers?

A strong answer checks each active reader against the write pointer with the wrap bit and ORs the results, and explains why this avoids computing the minimum read pointer.

2. Can a push be accepted when the FIFO is full?

A strong answer says yes if every full reader pops in the same cycle, and that one full reader that does not pop blocks it.

3. A new consumer joins mid-stream. Where does its pointer start?

A strong answer starts it at the write pointer, explains why older data is not safe to read, and covers the same-cycle push.

4. One consumer hangs. What happens and what would you add?

A strong answer traces the stall from that reader to the writer to every other reader, and proposes a watchdog with detach and error reporting.

5. How would you build this on a single-port SRAM?

A strong answer time-shares the read port with a small prefetch buffer per reader, or banks the storage, and discusses the extra latency and the arbitration.

Where it is used in real chips

Multi-reader FIFOs appear in trace and debug paths that feed several sinks, in packet mirroring for monitoring, in accelerators where several compute units consume the same input stream, and in display and image pipelines where several filters read the same line of pixels. They also appear inside NoC routers and DMA engines as shared buffers with independent read cursors.

The rest of the series

Part 28 covered the low-power FIFO, with clock gating and banks that sleep when empty.

Part 30 looks at the other way to serve many consumers: a broadcast FIFO, where one entry is delivered to every subscriber before it leaves.

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!