RTL Foundations / F13

Timing and Pipelines: What If the Work Does Not Fit in One Cycle?

Follow the collector's add, compare and shift path, calculate setup and hold margins, and verify sample alignment through an extra stage.

Lesson film

Film chapters

TranscriptCaptionsDownload film

Before reporting a reading, the collector adds three to its eight-bit input. If the sum is at least hexadecimal 050, it shifts the sum right by the amount supplied with that reading. The F12 testbench can compare the results one by one. There is a second question. Can the result settle at the receiver’s D input early enough to meet setup time before the next rising edge?

Follow the path from one register to the next

The input register saves the reading, shift amount, tag and valid bit. After it captures those fields on a rising edge, the sample enters the adder. The sum takes nine bits because FF + 3 can reach 102. The sum feeds both a comparator and a variable shifter. The comparator controls a mux that chooses the sum or the shifted value. On the next rising edge, the output register saves the result, tag and valid bit.

The baseline puts the add, compare, shift and mux between two registers. The extra-stage design stores the sum and its related fields before the compare, shift and mux.
The baseline has one cycle for the combinational path. The added register gives the adder and the remaining logic one cycle each.

After launch, the input register takes a clock-to-Q delay before Q settles. The result then takes time to travel through the combinational path to the receiver’s D input. The receiver also needs data to be stable for a minimum time before its edge. That interval is the setup time. Even a correct calculation can leave too little setup time if the result arrives late.

How much time is left before the next edge?

Use a teaching example with zero skew and no clock uncertainty. The period is 5 ns. Assume a maximum clock-to-Q delay of 0.8 ns and a setup time of 0.7 ns. That leaves 5.0 − 0.8 − 0.7 = 3.5 ns for the combinational path.

Assume that addition takes 2.5 ns. The longest path through the remaining compare, shift and mux logic takes 3.0 ns. The path needs 0.8 + 2.5 + 3.0 + 0.7 = 7.0 ns. It exceeds the 5 ns budget by 2 ns. Now put a register after the adder. Each segment has its own launch delay and capture setup time. The first segment needs 4.0 ns and the second 4.5 ns. Both fit the assumed period, with setup slack of 1.0 ns and 0.5 ns.

In the teaching example the unsplit path needs 7.0 ns. The adder stage needs 4.0 ns and the second stage 4.5 ns. Both new stages fit a 5 ns period.
The delay numbers illustrate the budget. The functional test uses a 10 ns clock and has no physical cell delay model.

How long must the old value stay after the same edge?

The setup check follows the slowest new data toward the next edge. The hold check starts with what the receiving register sampled on this edge. The old value must stay at D for a short time after capture. The earliest change matters here, so use minimum clock-to-Q and the shortest data path.

Now let the capture clock arrive 0.15 ns after the launch clock. This is positive capture skew. Use the launch edge as time zero. The receiving register samples at 0.15 ns and has an assumed hold time of 0.25 ns, so the old value must stay through 0.40 ns. A minimum clock-to-Q of 0.20 ns and a minimum logic delay of 0.10 ns let new data reach it at 0.30 ns. Hold slack is 0.30 − 0.40 = −0.10 ns.

The capture edge arrives at 0.15 ns. Old data must remain through 0.40 ns, but new data can arrive at 0.30 ns, giving negative 0.10 ns of hold slack.
Both times belong to the same sampling edge. Moving the following edge farther away leaves this hold check unchanged.

In this single-clock, same-edge example, a longer period changes none of the terms above. To address the failure, check the minimum data path and the clock arrival times at both registers. Then recheck setup after any change. Static timing analysis uses the target library, timing constraints, clock and path data, clock uncertainty, and the analysis conditions.

Which valid bit belongs to which result?

Use A=31 and B=52 from F12 and add C=A0. They enter the input register at E1, E2 and E4. Valid is zero at E3. That leaves a bubble, with no new sample to count.

SampleInput rising edgeNine-bit sumShiftResultBaseline output updateExtra-stage output update
AE10340034E2E3
BE2055102AE3E4
BubbleE3valid=0E4E5
CE40A32028E5E6

The baseline writes A to the output at E2. With an extra stage, E2 saves A’s sum, shift, tag and valid. E3 writes it to the output. A receiver on the same clock samples the already settled output at the following edge. For A, delivery is at E3 in the baseline and E4 with the extra stage. The table shows the output register’s update times.

The simulation shows A, B and C at the baseline output after E2, E3 and E5. The pipeline delays each result and its valid bit by one edge, with valid low after E5.
The waveform comes from Icarus VCD. It labels results only while valid is high. The input bubble at E3 reaches the extra-stage output after E5.

The faulty version routes the sum, shift and tag through the added register. Its valid bit still moves directly from input to output. At E2 the output says it has a result even though A has yet to arrive. Check the fields that travel with every sample. A comparison that only checks data can miss a result announced at the wrong time.

When is an extra stage worth adding?

At the same clock period, the baseline takes one cycle from input capture to output availability. The extra stage takes two. That wait is the latency. Both can accept one sample and deliver one result per cycle when filled. A second sample can enter before the first reaches the end. That overlap supports the throughput.

Suppose setup were the only limit in our teaching example. At a 7 ns period the baseline takes about 7 ns to make one result available. With two cycles at 5 ns, the extra-stage design takes 10 ns for that same result. Once filled, it can deliver a result every 5 ns. Compare these tradeoffs using the timing, rate and storage needs of the real design.

This lab keeps the receiver always ready. If it stalls, the final stage must hold the unaccepted result and valid bit. Earlier stages with samples in flight must either hold their entire sample when the next stage has no room or have enough buffering to absorb those samples. Check capacity before accepting more input to preserve the F11 delivery contract.

Replay the data and inspect the structure

Download the lab package, extract it on Linux or WSL and run bash run.sh. Icarus 12.0 checks four deliveries per design, including the nine-bit boundary FF + 3 = 102. The same test catches early valid at E2.

In the Yosys 0.33 generic structure both versions have one adder, comparator, variable shift and mux. Compare counts using the recorded flow and units.

Tool evidenceBaselineExtra stage
Register bits2539
Generic cells from synth -noabc97112
Physical timing or maximum frequencyNot analyzedNot analyzed

See the run summary, raw waveform and evidence with hashes.

Transfer question: B is waiting at the output and C is one stage back

Suppose the receiver stalls with valid B in the output stage, valid C in the middle stage, and D already accepted into the input stage. What must stay in the pipeline? If all stages stall together, can the input take another sample?

Answer

B, C and D are already in flight. Preserve their data and valid bits, along with their tags and related fields. A global stall must also stop the input from accepting a new sample. With independent stage control, unused space can still accept a sample if each stage follows a valid and ready contract.

The next lesson delivers the same report to a manager on a different clock. Once the two sides have separate rising edges, whether a short valid pulse is visible depends on when the receiver samples.

At which edge does A appear?

The source sends A, B and C on E1, E2 and E4, with a bubble at E3. The receiver is always ready. Change the pipeline and inspect the output register just after each rising edge.

For this timing exercise, assume 0.8 ns maximum clock-to-Q, 0.7 ns setup and logic delays of 2.5 and 3.0 ns. Use zero clock skew for the setup calculation.

Download RTL, testbench and results

Check your understanding

1. At a 5 ns period, maximum clock-to-Q is 0.8 ns and setup time is 0.7 ns. Assume zero skew and uncertainty. What remains for combinational logic?
2. New data can arrive at 0.30 ns. The old value must stay to 0.40 ns. What happens if only the clock period grows?
3. The collector samples B at E2. When does the extra-stage version update its output for B, and when can the same-clock receiver accept it?
4. The baseline has 25 register bits and the extra-stage version has 39. Both Yosys reports show the same operator types. What do these reports establish?
5. Valid B, C and D occupy the output, middle and input stages. The receiver stalls and all three stages pause. What should the pipeline do?