---
title: Latches and time borrowing
heading: Two-phase latch timing, borrowing across half cycles, skew tolerance and pulsed latches
eyebrow: S3 · Lesson 17 · Latches and time borrowing
xp: 50
---

::: hook
Flip-flops give every pipeline stage exactly one clock period, no more and no less: a stage with 0.7 ns of logic and a neighbor with 0.3 ns both get the same cycle, and the slow one sets it. Latches are transparent for half the clock, so data that arrives late at a latch passes straight through and simply leaves less time for the next stage. That **time borrowing** lets unbalanced logic share the cycle, hides clock skew, and is why the fastest custom processors have used latch-based timing for decades.
:::

::: play
- The curves are the shortest clock period for 1 ns of logic split between two half-cycle stages, a fraction x in the first and the rest in the second.
- With a flip-flop at each half-cycle boundary, each half must fit its own stage plus the flip-flop's overhead, so the period grows as the split becomes uneven.
- With latches the halves share the cycle: the period is the total logic plus two latch delays, whatever the split.
:::

```sim plot
view: graph
x: x = 0.1..0.9
y: T = 0..2.5 ns
slider: d = 20..100 = 50 ps
slider: q = 50..200 = 100 ps
plot: 1 + 2*d/1000 + 0*x | label: two-phase latches
plot: 1 + abs(2*x - 1) + 2*q/1000 | label: flip-flops every half cycle
```

::: predict
## A two-phase latch design has 0.7 ns of logic in one half cycle and 0.3 ns in the other, and its latches have 50 ps from D to Q. What is the shortest clock period, and what does the first half do?

- [x] 1.1 ns; the first half borrows 0.2 ns from the second
- [ ] 1.5 ns, set by the slow half at twice its delay
- [ ] 1.0 ns; latches add no overhead
- [ ] 1.1 ns, but only if the halves are rebalanced

::: reveal
Over a full cycle the data passes both blocks and two latches: $0.7 + 0.3 + 2 \times 0.05 = 1.1$ ns. Half a period is 0.55 ns, but the first block's result arrives $0.05 + 0.7 = 0.75$ ns after its latch opened, 0.2 ns after the second latch opened. That latch is transparent, so the data flows on, borrowing 0.2 ns that the quick second half gives back.
:::
:::

::: nameit
## Latches

A positive latch is **transparent** while the clock is high, passing D to Q with delay $t_{DQ}$, and **opaque** while it's low, holding its value. Its setup and hold times refer to the closing (falling) edge.

## Two-phase timing

Alternate latches on the two clock phases with logic between them. Over each cycle, data passes two logic blocks and two latches:
$$T \ge t_1 + t_2 + 2t_{DQ}$$
The sequencing overhead is $2t_{DQ}$, against $t_{clk\text{-}q} + t_\text{setup}$ (plus skew) for flip-flops.

## Borrowing

A block may run past its half cycle as long as its data reaches the next latch before that latch closes:
$$t_\text{borrow} \le \frac T2 - t_\text{setup} \;(- t_\text{skew})$$
Borrowing passes slack along a chain of stages; the cycle-level constraint still holds on average, so a pipeline that's too slow overall accumulates borrowing until a latch's setup fails.

## Skew and hold

While data arrives during the transparent phase, clock skew doesn't steal time: latch designs have **soft edges**. Hold is the hard part: a latch's input must stay stable after its closing edge, while the previous latch may already be open. Nonoverlapping clock phases with a gap $t_\text{no}$ help:
$$t_\text{min} \ge t_\text{hold} + t_\text{skew} - t_{ccq} - t_\text{no}$$

## Pulsed latches

A latch transparent only for a short pulse $t_\text{pw}$ after each edge acts like a flip-flop with little overhead and some borrowing, at the price of a hold requirement $t_\text{pw}$ longer.
:::

::: example
## A flip-flop design has 1.0 ns of logic per stage, 80 ps clock-to-Q, 50 ps setup and 100 ps of clock skew. A two-phase latch version splits the same logic into two halves with 50 ps latches. Compare their clock periods.

::: solution
1. **Flip-flop period.**
   $$\begin{aligned} T &= 1.0 + 0.08 + 0.05 + 0.1 \\ &= 1.23\ \text{ns} \end{aligned}$$
2. **Latch period.**
   $$\begin{aligned} T &= 1.0 + 2 \times 0.05 \\ &= 1.1\ \text{ns} \end{aligned}$$
   as long as data arrives while the latches are transparent, since skew then shifts when a latch opens but not when the data gets through.
3. **Compare.**
   $$1 - \frac{1.1}{1.23} = 11\%$$
   shorter, mostly from absorbing the skew.

**Answer:** 1.23 ns with flip-flops and 1.1 ns with latches, 11% shorter.
:::
:::

::: example
## In the 1.1 ns latch design, how much more could the first half borrow, with 30 ps of setup?

::: solution
1. **Latest allowed arrival.** Data may arrive this long after the second latch opens:
   $$\begin{aligned} t &= \frac{T}{2} - t_\text{setup} \\ &= 0.55 - 0.03 \\ &= 0.52\ \text{ns} \end{aligned}$$
2. **What's left.** It arrives 0.2 ns after, so
   $$0.52 - 0.2 = 0.32\ \text{ns}$$
   of borrowing remains.
3. **How far the first block could grow.** The setup window alone would let it reach $0.7 + 0.32 = 1.02$ ns, but the total must stay within the cycle, so the second block has to shrink to match. With only 0.3 ns to give, the first block can reach 1.0 ns.

**Answer:** 0.32 ns more.
:::
:::

::: example
## A pulsed latch is transparent for 80 ps after each clock edge; its hold time is 20 ps and its contamination clock-to-Q is 40 ps. How short may a path between two of them be?

::: solution
1. **The hold condition.** The receiving latch stays open for the pulse, so new data must not arrive before the pulse ends plus the hold time:
   $$\begin{aligned} t_\text{min} &\ge 20 + 80 - 40 \\ &= 60\ \text{ps} \end{aligned}$$
2. **The cost.** Short paths get delay buffers inserted, the price of the pulsed latch's small setup overhead.

**Answer:** no shorter than 60 ps.
:::
:::

::: check
kind: parts
given: a = 0.6 | 0.8; b = 0.2 | 0.4; d = 40 | 60; s = 20 | 40

## A two-phase latch design has {a} ns of logic in its first half cycle and {b} ns in its second; latches take {d} ps from D to Q and need {s} ps of setup.

::: part
answer: a + b + 2*d/1000
unit: ns
tolerance: 0.5%

### What is the shortest clock period?

::: misses
- [a + b] Add two latch delays per cycle.
- [any] $t_1 + t_2 + 2t_{DQ}$.
:::
:::

::: part
answer: (a - b)/2
unit: ns
tolerance: 0.5%

### At that period, how much does the first half borrow?

::: misses
- [any] Arrival time $t_{DQ} + t_1$ minus the half period.
:::
:::

::: part
answer: (a + b + 2*d/1000)/2 - s/1000
unit: ns
tolerance: 0.5%

### What is the most it could borrow?

::: misses
- [any] $T/2 - t_\text{setup}$.
:::
:::
:::

::: check
kind: parts
given: L = 1 | 2; q = 100 | 150; k = 50 | 100; d = 40 | 60

## A stage has {L} ns of logic. Flip-flops cost {q} ps of clock-to-Q plus setup, the clock has {k} ps of skew, and latches have {d} ps from D to Q.

::: part
answer: L + q/1000 + k/1000
unit: ns
tolerance: 0.5%

### What period does the flip-flop design need?

::: misses
- [L + q/1000] Skew adds to a flip-flop path.
- [any] $t_\text{logic} + t_{clk\text{-}q} + t_\text{setup} + t_\text{skew}$.
:::
:::

::: part
answer: L + 2*d/1000
unit: ns
tolerance: 0.5%

### And the two-phase latch design, with data arriving while the latches are transparent?

::: misses
- [any] Two latch delays; the soft edges absorb the skew.
:::
:::
:::

::: check
kind: parts
given: h = 10 | 20; w = 60 | 100; c = 30 | 50; k = 0 | 20

## Pulsed latches are transparent for {w} ps, with {h} ps hold and {c} ps contamination clock-to-Q; the clock has {k} ps of skew.

::: part
answer: h + w - c + k
unit: ps
tolerance: 0.5%

### How short may a path between two of them be?

::: misses
- [h - c + k] The receiving latch stays open for the pulse width.
- [any] $t_\text{hold} + t_\text{pw} - t_{ccq} + t_\text{skew}$.
:::
:::
:::

::: check
kind: choice

## Why can a latch-based pipeline tolerate clock skew that would slow a flip-flop pipeline?

- [ ] Latches are faster than flip-flops
- [x] Data that arrives while a latch is transparent passes straight through, so a latch opening a little early or late doesn't change when the data reaches the next stage
- [ ] Latches don't need a clock tree
- [ ] Skew only affects hold times

::: misses
- [1] A latch's D-to-Q delay is similar to a flip-flop's clock-to-Q; the advantage is in when the edges matter.
- [3] Latch designs need two balanced clock phases, usually harder to distribute.
- [4] In flip-flop designs skew eats directly into setup time.
:::
:::

::: check
kind: match

## Match each term to its meaning.

- Transparent :: the latch passes D to Q while its clock phase is active
- Time borrowing :: a block finishing after its half cycle, using a latch's open window
- Nonoverlap gap :: time when neither clock phase is high, protecting hold
- Soft edge :: timing that skew doesn't move as long as data arrives while the latch is open
- [extra] a flip-flop's setup window

::: misses
- [any] Think of what a latch does while it's open and while it's closed.
:::
:::

::: check
kind: derivation
vars: T = 0.2..5, a = 0.05..2, d = 0.01..0.1, s = 0.01..0.1

## A two-phase latch design runs at period T; its first half-cycle block has delay a, and its latches have D-to-Q delay d and setup s.

::: step
answer: d + a - T/2

### How much does the first block borrow, if positive?
:::

::: step
answer: T/2 - s

### What is the most any block can borrow?
:::

::: step
answer: T - 2*d - a

### How much time does that leave the second block over the full cycle?
:::

::: right
Right. Borrowing moves time between halves; the cycle as a whole still has to fit.
:::
:::

::: check
kind: python

## Write `latch_pipeline(delays, T, t_dq, t_su)`: data leaves the first latch at $t_{DQ}$ after time 0; latch i (i = 1, 2, …) opens at iT/2 and closes at (i + 1)T/2. Data reaches latch i at the previous latch's output time plus delays[i − 1], must arrive at least t_su before it closes, and leaves at max(arrival, opening) + t_dq. Return (ok, borrows), where borrows lists max(0, arrival − opening) for each latch.

```python starter
def latch_pipeline(delays, T, t_dq, t_su):
    return (True, [0.0] * len(delays))
```

```python solution
def latch_pipeline(delays, T, t_dq, t_su):
    out, ok, borrows = t_dq, True, []
    for i, d in enumerate(delays, start=1):
        opening, closing = i * T / 2, (i + 1) * T / 2
        arrival = out + d
        if arrival > closing - t_su + 1e-12:
            ok = False
        borrows.append(max(0.0, arrival - opening))
        out = max(arrival, opening) + t_dq
    return (ok, borrows)
```

```python tests
ok, b = latch_pipeline([0.7, 0.3] * 4, 1.1, 0.05, 0.03)
assert ok and abs(b[0] - 0.2) < 1e-9 and abs(b[1]) < 1e-9, "The predict: 1.1 ns works, borrowing 0.2 ns in each slow half."
ok2, b2 = latch_pipeline([0.7, 0.3] * 4, 1.0, 0.05, 0.03)
assert not ok2 and b2[4] > b2[2] > b2[0], "Too fast: borrowing grows stage by stage until setup fails."
```

::: right
Right. Borrowing can carry a deficit for a while, but a clock that's too fast on average always fails eventually.
:::
:::

::: explain
## What is time borrowing, and why does it help when pipeline stages are unbalanced?

::: model
In a latch-based design, a latch is transparent for half of each cycle. If the logic before it finishes late, after the latch has opened, the data simply passes through the open latch and continues into the next block of logic, which then has less time. The late block has borrowed time from the next one. With flip-flops, each stage's result is captured at a fixed edge, so the slowest stage sets the clock and quick stages waste their slack. With latches, a slow block and a quick neighbor share their combined time, so the cycle only has to cover the average, the total logic over the cycle plus the latch delays.
:::
:::

::: practice
::: check
given: a = 0.5 | 0.9; b = 0.1 | 0.3; d = 30 | 50
answer: a + b + 2*d/1000
unit: ns
tolerance: 0.5%

## Two-phase period with {a} and {b} ns of logic and {d} ps latches?

::: misses
- [any] $t_1 + t_2 + 2t_{DQ}$.
:::
:::

::: check
given: T = 1 | 2; s = 20 | 50
answer: T/2 - s/1000
unit: ns
tolerance: 0.5%

## Largest borrow at T = {T} ns with {s} ps setup?

::: misses
- [any] $T/2 - t_\text{setup}$.
:::
:::

::: check
given: h = 15 | 25; w = 50 | 90; c = 35 | 45
answer: h + w - c
unit: ps
tolerance: 0.5%

## Minimum path between pulsed latches: hold {h}, pulse {w}, contamination {c} ps?

::: misses
- [any] $t_\text{hold} + t_\text{pw} - t_{ccq}$.
:::
:::
:::
