Register Slices: Timing Closure in the Interconnect

Your interconnect is correct, and it is too slow for the clock. One row of flip-flops can repair that, if you put it in the right wires.

You Will Be Able To

  • Trace the forward path and the backward path of a channel, and say why a long one fails timing.
  • Show what a forward slice does to a run of beats, and what it costs.
  • Explain why ready cannot be cut with a flip-flop alone, and what the spare register is for.
Lesson
S4.7
Time
27 min
Runs on
Your browser
Check
5 questions

The timing report names one path as too long. It starts at a manager, crosses a decoder, an arbiter and a multiplexer, and ends in a memory. A colleague adds a flip-flop on the ready wire. The path is shorter, and the memory now holds one word twice.

Before You Start

You need the handshake from S0.3: a transfer happens at a clock edge with both wires high. You need the decoder, the arbiter and the grant from Many Managers.

You need the beat from Bursts, Locks and the Waiting Request. AXI in one picture names the AXI channels, which this page mentions once.

Five questions this page answers
Question
1Which two paths does every channel have, and where do they start and end?
2Why does a path through several hops fail timing?
3What does a forward slice change for the beats, and what does it leave alone?
4Why does a flip-flop on ready alone lose and repeat beats?
5What does the spare register of a backward slice hold, and when?

The Idea: Cut a Long Path with Flip-Flops

A channel is a group of wires that carries beats one way. The sender drives valid and the payload, which is everything the beat carries. The receiver drives ready. A beat moves at a clock edge that sees valid and ready at 1.

So a channel has two paths. The forward path carries valid and the payload from sender to receiver. The backward path carries ready from receiver to sender.

Inside an interconnect, both paths cross logic. Each decoder, arbiter and multiplexer on the way is one hop. A signal must cross every hop between two flip-flops within one clock period. With enough hops it arrives too late. The path then fails timing.

The cure is a register slice: a row of flip-flops placed in the channel. It cuts one long path into two short ones. Each beat now takes one more clock cycle to arrive. Getting every path under the clock period is called timing closure.

Cutting the forward path is easy. Cutting the backward path is the hard part, and the reason this page exists.

New Words

New words on this page
WordMeaning
ValidThe wire of the sender. At 1 it says: this beat is real.
ReadyThe wire of the receiver. At 1 it says: I take a beat at this edge.
PayloadEverything a beat carries beside valid: address, data, control bits.
Forward pathThe path of valid and the payload, from sender to receiver.
Backward pathThe path of ready, from receiver to sender.
Timing pathThe logic between one flip-flop and the next. Its delay must fit in one clock period.
Register sliceFlip-flops placed in a channel to cut a timing path. A slice for short.
Forward sliceA slice with flip-flops on valid and the payload. Ready passes through as logic.
Backward sliceA slice whose ready comes from a flip-flop. It has a spare register for one beat.
Skid bufferThe engineers' name for that spare register, and often for the whole backward slice.

Latency on this page is the number of clock edges from the sender handing a beat over to the receiver taking it.

One Picture: Two Paths and a Cut

One Channel, Two Paths, and a Place to CutStep through the picture. A channel crosses two hops of an interconnect on its way to the receiver.
  • Processor
  • Bus
  • Control / FSM
  • Memory
One Channel, Two Paths, and a Place to CutStep through the picture. A channel crosses two hops of an interconnect on its way to the receiver. component Sender a flip-flop drivesvalid and the payload component Hop 1 a decoder, an arbiterand a multiplexer:pure logic component Register slice flip-flops placed inthe channel component Hop 2 the same three piecesagain component Receiver a flip-flop takes thebeat, and logic drivesready valid, payloadvalid, payloadvalid, payloadvalid, payloadreadyreadyreadyready
  1. component Sendera flip-flop drives valid and the payload
    • valid, payload → Hop 1
  2. component Hop 1a decoder, an arbiter and a multiplexer: pure logic
    • valid, payload → Register slice
    • ready → Sender
  3. component Hop 2the same three pieces again
    • valid, payload → Receiver
    • ready → Register slice
  4. component Receivera flip-flop takes the beat, and logic drives ready
    • ready → Hop 2
  5. component Register sliceflip-flops placed in the channel
    • valid, payload → Hop 2
    • ready → Hop 1
  1. The forward path

    Valid and the payload leave a flip-flop at the sender. They cross both hops as logic and reach a flip-flop at the receiver.

  2. The backward path

    Ready travels the other way. It crosses the same hops, and must reach the sender before the same clock edge.

  3. A forward slice

    Flip-flops on valid and the payload. The forward path is now two short paths. Ready still crosses the slice as logic.

  4. A backward slice

    A flip-flop drives ready to the sender. The slice needs one spare register, for the beat that is already under way.

Read the diagram as text
  • Sender: a flip-flop drives valid and the payload
  • Hop 1: a decoder, an arbiter and a multiplexer: pure logic
  • Register slice: flip-flops placed in the channel
  • Hop 2: the same three pieces again
  • Receiver: a flip-flop takes the beat, and logic drives ready
  • Sender → Hop 1: valid, payload
  • Hop 1 → Register slice: valid, payload
  • Register slice → Hop 2: valid, payload
  • Hop 2 → Receiver: valid, payload
  • Receiver → Hop 2: ready
  • Hop 2 → Register slice: ready
  • Register slice → Hop 1: ready
  • Hop 1 → Sender: ready

Each arrow stands for a group of wires. Without the slice, both paths cross two hops between flip-flops.

Notice the directions. The forward path runs left to right, and the backward path runs right to left. A slice can cut one of them, or both.

The Smallest Example, Worked by Hand: A Forward Slice

A forward slice is one register with a rule: load a new beat whenever the register is empty or is being emptied. The sender has four beats, a1 to a4. The receiver is ready at every edge but the third.

Four beats through a forward slice, by hand
EdgeSender offersRegister showsReceiver readyWhat the edge does
1a1nothingyesthe register loads a1
2a2a1yesthe receiver takes a1; the register loads a2
3a3a2nonothing moves: the register is full and not being emptied
4a3a2yesthe receiver takes a2; the register loads a3
5a4a3yesthe receiver takes a3; the register loads a4
6nothinga4yesthe receiver takes a4

Every beat arrives, in order, one edge later than it was handed over. With wires in place of the slice, the last beat would be taken at edge 5. Here it is edge 6.

Look at edge 3 again. The sender must know, in that same cycle, that nothing can be loaded. So "receiver not ready" still travels back through the slice as logic. The forward path is cut. The backward path is not.

The Rules

  1. Rule 1: A slice may change when a beat arrives, and nothing else.

    Every beat that is handed over is taken once, in the same order.

  2. Rule 2: Valid and the payload are registered together.

    They pass the same number of flip-flops. A valid that arrives ahead of its payload marks the wrong data.

  3. Rule 3: Each slice in a channel adds one cycle of latency.

    Two slices in a row add two cycles.

  4. Rule 4: A ready that comes from a flip-flop is one cycle old.

    When the receiver stops, the sender learns it one cycle later. It may hand over one more beat first.

  5. Rule 5: So a backward slice keeps one spare register.

    It catches that one beat. While the spare register is full, the slice tells the sender to wait.

  6. Rule 6: A slice does not make a hop shorter.

    It stops the delays of hops from adding up. Put it between hops.

Sources for These Rules

Arm AMBA AXI Protocol Specification, document IHI 0022, issue L, section A2.5. A register stage may be placed in any channel, at the cost of a cycle of latency. Valid must pass the same number of stages as its payload. Section A2.1.1 forbids logic paths from the inputs of an interface to its outputs.

The forward slice, the backward slice, the spare register and the name "skid buffer" are common practice. The specification does not describe how a slice is built.

The RTL track builds the same spare register inside a pipeline stage, in Stalls, Backpressure and the Skid Buffer.

Now Run It

The lab at the end of this page is the hand example as a circuit. Test code plays the sender and the receiver, and prints what each side sees at every clock edge.

Recorded from the lab on Icarus, with the forward slice. The word "up" marks the sender's side of the slice, and "down" the receiver's side. The value xx is a register that holds nothing yet.
e1 up: valid=1 data=a1 ready=1 | down: valid=0 data=xx ready=1 | handed over a1, taken --
e2 up: valid=1 data=a2 ready=1 | down: valid=1 data=a1 ready=1 | handed over a2, taken a1
e3 up: valid=1 data=a3 ready=0 | down: valid=1 data=a2 ready=0 | handed over --, taken --
e4 up: valid=1 data=a3 ready=1 | down: valid=1 data=a2 ready=1 | handed over a3, taken a2
e5 up: valid=1 data=a4 ready=1 | down: valid=1 data=a3 ready=1 | handed over a4, taken a3
e6 up: valid=0 data=a5 ready=1 | down: valid=1 data=a4 ready=1 | handed over --, taken a4
e7 up: valid=0 data=a5 ready=1 | down: valid=0 data=a5 ready=1 | handed over --, taken --
handed over 4, taken 4: a1 a2 a3 a4
last beat taken at e6

Rule 3 at work: a1 is handed over at e1 and taken at e2. Rule 1 at work: the last line lists four beats, in order.

Four Beats Through a Forward Slice, RecordedStep through the clock edges. The top three lanes are the sender's side, the bottom three the receiver's side.
012345clkup validup dataa1a2a3a4a5up readydown validdown data0a1a2a3a4down ready
Scroll horizontally ↔
  1. Cycle 0

    The sender hands over a1. The register is still empty, so the receiver sees no valid beat.

  2. Cycle 1

    The register shows a1 and the receiver takes it. At the same edge the register loads a2.

  3. Cycle 2

    The receiver is not ready. Ready passes through the slice as logic, so the sender sees 0 in the same cycle.

  4. Cycle 3

    The receiver is ready again. It takes a2, and the register loads a3.

  5. Cycle 4

    The receiver takes a3. The sender hands over its last beat, a4.

  6. Cycle 5

    The receiver takes a4, one edge after the sender gave it.

Recorded from the lab. Each column is what one rising clock edge sees. The register is empty at the first edge; the figure draws its data as 0 there.

Now the backward slice, with the same sender and the same receiver.

The same lab with bwd_slice as the piece in the middle.
e1 up: valid=1 data=a1 ready=1 | down: valid=1 data=a1 ready=1 | handed over a1, taken a1
e2 up: valid=1 data=a2 ready=1 | down: valid=1 data=a2 ready=1 | handed over a2, taken a2
e3 up: valid=1 data=a3 ready=1 | down: valid=1 data=a3 ready=0 | handed over a3, taken --
e4 up: valid=1 data=a4 ready=0 | down: valid=1 data=a3 ready=1 | handed over --, taken a3
e5 up: valid=1 data=a4 ready=1 | down: valid=1 data=a4 ready=1 | handed over a4, taken a4
e6 up: valid=0 data=a5 ready=1 | down: valid=0 data=a5 ready=1 | handed over --, taken --
e7 up: valid=0 data=a5 ready=1 | down: valid=0 data=a5 ready=1 | handed over --, taken --
handed over 4, taken 4: a1 a2 a3 a4
last beat taken at e5

Rule 4 at work: at e3 the receiver is not ready. The sender still sees ready at 1 and hands over a3. Rule 5 at work: the spare register keeps a3. At e4 the sender sees ready at 0, and the receiver takes a3 from the spare register.

This slice adds no latency while the receiver keeps up: the last beat is taken at e5, as with wires. Valid and the payload pass straight through it.

How much shorter do the paths get? The lab channel has no hops, so it cannot say. A second design can: a path of two hops between flip-flops, built by a synthesis tool. The tool reports the longest path in logic levels. One level is one gate, so a path of 15 levels crosses 15 gates in a row.

The longest path of a two-hop design, measured
Between the two hopsLongest path, in logic levels
nothing15
a forward slice9
a backward slice19

Measured with Yosys 0.70+290, generic gates. The numbers belong to this small design and this tool.

The forward slice does its job: 15 levels become 9. The backward slice alone makes the longest path longer, 19 levels. That is not a mistake in the measurement.

In this design the longest path is the forward one, and the backward slice does not cut it. Worse, each hop works out ready from its grant, and the grant from valid. So the input of the spare register sits at the end of a path that starts on the forward side.

The lesson of the table is rule 6 with a warning. Find the path that is too long before you choose a slice. A cut in the other path costs flip-flops and buys nothing.

The Hop of the Measured Design
One hop: an address decoder, an arbiter over four senders, a multiplexer, and ready for the winner. The measured design has two of them in a row.
// One hop of an interconnect, for one channel: decode, arbitrate, select.
module hop #(parameter logic [7:0] BASE = 8'h10) (
  input  logic [3:0]        valid,              // four senders
  input  logic [3:0][15:0]  addr,
  input  logic [3:0][7:0]   data,
  output logic [3:0]        ready,
  output logic              out_valid,
  output logic [15:0]       out_addr,
  output logic [7:0]        out_data,
  input  logic              out_ready
);
  logic [3:0] want, grant;
  always_comb begin
    for (int i = 0; i < 4; i++) want[i] = valid[i] && (addr[i][15:8] == BASE);   // the decoder
    grant = want & (~want + 4'd1);                                              // the arbiter: lowest number first
    out_valid = |want;
    out_addr = '0;  out_data = '0;
    for (int i = 0; i < 4; i++) if (grant[i]) begin out_addr = addr[i]; out_data = data[i]; end   // the multiplexer
    ready = grant & {4{out_ready}};                                             // ready goes back to the winner
  end
endmodule

These labs leave things out. The lab channel is eight bits wide and has one sender. Logic levels ignore the length of the wires, which on a real chip is often the larger part of the delay.

Why It Is Built This Way

Design choiceThe alternativeWhat the choice buys, and costs
Cut the path with a sliceSlow the clock for the whole chipOnly the beats of this channel pay, with one cycle each. The slice costs flip-flops.
A forward slice where the forward path is longA slice on both paths everywhereOne register per payload bit. Ready still crosses as logic, so the backward path stays whole.
A spare register behind a registered readyTell the receiver to announce a stop one cycle earlyAny sender and any receiver can be joined. The spare register costs as much as the main one.

A handshake makes all of this possible. Neither side counts cycles. Each only watches valid and ready, so a slice in the middle changes nothing that either side relies on.

The Trap: A Flip-Flop on Ready, and Nothing Else

Back to the colleague from the top of the page. The ready path was too long, so they put one flip-flop in it. Here is that circuit in the lab, with the same sender and receiver.

The same lab with late_ready as the piece in the middle: a flip-flop on ready, and no spare register.
e1 up: valid=1 data=a1 ready=0 | down: valid=1 data=a1 ready=1 | handed over --, taken a1
e2 up: valid=1 data=a1 ready=1 | down: valid=1 data=a1 ready=1 | handed over a1, taken a1
e3 up: valid=1 data=a2 ready=1 | down: valid=1 data=a2 ready=0 | handed over a2, taken --
e4 up: valid=1 data=a3 ready=0 | down: valid=1 data=a3 ready=1 | handed over --, taken a3
e5 up: valid=1 data=a3 ready=1 | down: valid=1 data=a3 ready=1 | handed over a3, taken a3
e6 up: valid=1 data=a4 ready=1 | down: valid=1 data=a4 ready=1 | handed over a4, taken a4
e7 up: valid=0 data=a5 ready=1 | down: valid=0 data=a5 ready=1 | handed over --, taken --
handed over 4, taken 5: a1 a1 a3 a3 a4
last beat taken at e6

Read e3. The receiver is not ready. The sender sees the ready of one cycle ago, which was 1, and hands over a2. Nobody takes it, and nothing keeps it. The beat a2 is lost.

Read e4. Now the sender sees ready at 0 and holds a3. The receiver is ready and takes a3. At e5 the sender hands over a3, and the receiver takes it again. The beat a3 arrives twice.

The first two edges show the same fault. The flip-flop starts at 0, so the sender holds a1 while the receiver takes it. Then a1 is taken again.

The last line shows the damage: four beats handed over, five taken, and one of the four missing. No protocol rule was broken on either side. Each side saw a legal handshake. The count of beats is what gives the fault away, so compare the two counts first.

At Scale

This page1 channel, 1 slice
A large interconnecthundreds of channels

This section looks ahead. One slice in one channel is easy to follow. A large interconnect has hundreds of channels, and only some of them are slow.

  1. Five channels, five choices

    An AXI port has five channels. Each can have its own number of slices, because no channel depends on the cycle count of another.

  2. Both paths at once

    A slice that cuts both paths is called a full slice. The Full Slice builds one and counts what it costs.

  3. Wires, not gates

    On a large chip the delay of a bus path is mostly wire. A slice half-way along a long wire is common, even with no logic near it.

  4. The same idea in a pipeline

    The Protocols track counts the cycles of staged handshakes in its lesson on pipelining.

Try It

Run the lab. For each beat, find the edge that hands it over and the edge that takes it.

Change fwd_slice to bwd_slice in the line that places the piece. Find the edge where the spare register is full.

Change it to late_ready. Compare the two counts in the last line but one.

With bwd_slice, make the receiver stop for two edges in a row. Say how many beats the spare register must hold.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: e1 up: valid=1 data=a1 ready=1 | down: valid=0 data=xx ready=1 | handed over a1, taken -- e2 up: valid=1 data=a2 ready=1 | down: valid=1 data=a1 ready=1 | handed over a2, taken a1 e3 up: valid=1 data=a3 ready=0 | down: valid=1 data=a2 ready=0 | handed over --, taken -- e4 up: valid=1 data=a3 ready=1 | down: valid=1 data=a2 ready=1 | handed over a3, taken a2 e5 up: valid=1 data=a4 ready=1 | down: valid=1 data=a3 ready=1 | handed over a4, taken a3 e6 up: valid=0 data=a5 ready=1 | down: valid=1 data=a4 ready=1 | handed over --, taken a4 e7 up: valid=0 data=a5 ready=1 | down: valid=0 data=a5 ready=1 | handed over --, taken -- handed over 4, taken 4: a1 a2 a3 a4 last beat taken at e6

Check Yourself

Predict the outputThe lab runs with the backward slice. The receiver is not ready at e2 and at e3. What is the last line the lab prints?
// One channel with a backward slice in the middle. Test code sends 4 beats and prints every edge.
// ---- Forward slice: flip-flops on valid and data. ready passes through as logic. ----
module fwd_slice (
  input  logic       clk, rst,
  input  logic       up_valid,  input  logic [7:0] up_data,  output logic up_ready,
  output logic       dn_valid,  output logic [7:0] dn_data,  input  logic dn_ready
);
  assign up_ready = !dn_valid || dn_ready;      // room when the register is empty, or is being emptied now
  always_ff @(posedge clk)
    if (rst) dn_valid <= 1'b0;
    else if (up_ready) begin
      dn_valid <= up_valid;
      dn_data  <= up_data;
    end
endmodule

// ---- Backward slice: ready comes from a flip-flop. One spare register catches the beat under way. ----
module bwd_slice (
  input  logic       clk, rst,
  input  logic       up_valid,  input  logic [7:0] up_data,  output logic up_ready,
  output logic       dn_valid,  output logic [7:0] dn_data,  input  logic dn_ready
);
  logic       spare_full;                       // 1: the spare register holds a beat
  logic [7:0] spare_data;
  assign up_ready = !spare_full;                // from a flip-flop alone: no logic from dn_ready
  assign dn_valid = spare_full || up_valid;     // valid and data pass through, the spare beat first
  assign dn_data  = spare_full ? spare_data : up_data;
  always_ff @(posedge clk)
    if (rst) spare_full <= 1'b0;
    else if (!spare_full) begin
      if (up_valid && !dn_ready) begin          // a beat was handed over, and the receiver did not take it
        spare_full <= 1'b1;
        spare_data <= up_data;
      end
    end
    else if (dn_ready) spare_full <= 1'b0;      // the spare beat has gone on
endmodule
// ---- NOT a slice: a flip-flop on ready alone, with nowhere to keep a beat. ----
module late_ready (
  input  logic       clk, rst,
  input  logic       up_valid,  input  logic [7:0] up_data,  output logic up_ready,
  output logic       dn_valid,  output logic [7:0] dn_data,  input  logic dn_ready
);
  assign dn_valid = up_valid;
  assign dn_data  = up_data;
  always_ff @(posedge clk)
    if (rst) up_ready <= 1'b0;
    else     up_ready <= dn_ready;              // the sender sees ready one cycle late
endmodule

// ---- Test code: a sender, the piece in the middle, and a receiver that is not always ready ----
module tb;
  logic clk = 0, rst = 1;
  always #5 clk = ~clk;                          // "#5" waits 5 time units: one clock cycle is 10

  logic       up_valid, dn_ready = 0;
  logic [7:0] up_data;
  wire        up_ready, dn_valid;
  wire  [7:0] dn_data;
  bwd_slice piece (.*);                       // ".*" joins every port to the signal of the same name

  localparam int BEATS = 4;
  localparam logic [0:9] READY = 10'b1001111111;   // the receiver's ready at e1, e2, ...
  int sent = 0, taken = 0, n = 0, last = 0;
  string list = "", gave, took;
  assign up_valid = !rst && (sent < BEATS);      // the sender has a beat while any is left
  assign up_data  = 8'ha1 + sent[7:0];           // the beats are a1, a2, a3, ...

  always @(posedge clk) if (!rst) begin
    n++;
    gave = "--";  took = "--";
    if (up_valid && up_ready) begin              // a handshake on the sender's side
      gave = $sformatf("%h", up_data);
      sent <= sent + 1;
    end
    if (dn_valid && dn_ready) begin              // a handshake on the receiver's side
      took = $sformatf("%h", dn_data);
      list = {list, " ", took};
      taken++;  last = n;
    end
    $display("e%0d up: valid=%b data=%h ready=%b | down: valid=%b data=%h ready=%b | handed over %s, taken %s",
             n, up_valid, up_data, up_ready, dn_valid, dn_data, dn_ready, gave, took);
    dn_ready <= (n < 10) ? READY[n] : READY[9];
  end

  initial begin
    @(negedge clk);
    rst = 0;  dn_ready = READY[0];
    repeat (8) @(posedge clk);
    #1;
    $display("handed over %0d, taken %0d:%s", sent, taken, list);
    $display("last beat taken at e%0d", last);
    $finish;                                     // $finish ends the simulation
  end
endmodule
ConceptWhich signals travel on the backward path of a channel?
ConceptWhat does a forward slice leave uncut?
ConceptA flip-flop is placed on ready alone. The receiver stops for one cycle. What can happen?
ConceptWhen does the spare register of a backward slice hold a beat?

Common Mistakes

Wrong Put a flip-flop on ready and leave the rest of the channel alone.

The sender then acts on a ready that is one cycle old.

Fix Add the spare register, and tell the sender to wait while it is full.

Wrong Register the payload and let valid pass through.

Valid then marks the payload of the cycle before.

Fix Give valid and the payload the same number of flip-flops.

Wrong Add a slice wherever the timing report shows a bus signal.

A slice in the other path does not shorten the failing one.

Fix Read which path fails, forward or backward, and cut that one.

Remember

  • A channel has a forward path (valid, payload) and a backward path (ready). Each crosses every hop.
  • A register slice cuts a long path in two, and adds one cycle of latency.
  • A forward slice registers valid and the payload together. Ready still passes through it.
  • A registered ready is one cycle old, so a backward slice keeps a spare register for one beat.
  • A slice cannot shorten a hop. Find the long path first, then cut that one.

Practice

Report a problem with this page