S48 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

S4 · Lesson 8 · The front end

Fetch bandwidth, taken branches, instruction caches, decoders and micro-op caches

An out-of-order core can only execute what its front end delivers. Every cycle the front end must predict where the program goes, fetch the right bytes from the instruction cache, find where instructions start, decode them and rename them, at the full width of the machine. Taken branches cut fetch blocks short, instruction-cache misses leave the pipeline empty, and variable-length x86 instructions are expensive to decode. Front-end stalls are a large share of the CPI of big server programs, and much of a modern core's design goes into keeping the front end ahead.

  • The curve is the average fetch rate of a front end of width w when a taken branch ends a fetch block every t instructions and each redirection costs b bubble cycles: t/(⌈t/w⌉+b).
  • With no bubbles, short runs between taken branches still waste slots: a 4-wide fetch delivers only 3 per cycle when blocks are 6 long.
  • A bubble per taken branch hurts most when blocks are short, which is why the BTB must redirect fetch in the very next cycle.

Predict

A 4-wide front end fetches up to the first taken branch each cycle, with no extra bubbles. If a taken branch comes every 6 instructions, what fetch rate does it reach?

Name it

Fetch blocks

Each cycle the fetch unit reads an aligned block from the instruction cache and stops at the first predicted-taken branch. With runs of t instructions between taken branches, a w-wide fetch takes ⌈t/w⌉ cycles per run, plus b bubbles if redirecting isn't instantaneous:

fetch rate=t⌈t/w⌉+b

A decoupled front end runs the branch predictor ahead, filling a fetch target queue, so predictions and cache accesses overlap.

Instruction-cache misses

Big programs (databases, web servers, browsers) have instruction footprints of megabytes. An instruction-cache miss leaves the back end starved: a component of MPKI/1000× penalty in the CPI. Next-line and fetch-directed prefetching follow the predicted path to hide it.

Decoding

Fixed-length instructions decode in parallel trivially. x86 instructions are 1 to 15 bytes, so finding their boundaries is serial work; decoders handle a few instructions a cycle and translate them into micro-operations (µops).

The micro-op cache

A cache of already decoded µops, indexed by instruction address, bypasses the decoders. Delivering u µops a cycle when it hits (fraction h) and d from the decoders when it misses, the average rate is

1h/u+(1−h)/d

and it saves the decoders' power on every hit.

Worked example

A µop cache delivers 6 µops a cycle and hits 80% of the time; the legacy decoders deliver 4. What average rate does the front end reach?

Show the solution
  1. Time per µop. Rates combine as a harmonic mean, weighted by the share of µops each source delivers: t=0.8/6+0.2/4=0.183cycles
  2. Rate. 1/t=5.45µops a cycle
  3. A better hit rate. Raising the hit rate to 95% would give 5.85.

Answer the front end averages 5.45 µops a cycle.

Worked example

A server program misses the instruction cache 5 times per thousand instructions, and each miss costs 20 cycles from the L2. What CPI does that add to a core that would otherwise run at IPC 3?

Show the solution
  1. Added CPI. 5/1000×20=0.1 cycles per instruction.
  2. Compare with the ideal. An IPC of 3 is an ideal CPI of 0.33, so the misses make the core 30% slower.
  3. Why instruction misses hurt more. For the same program a data-cache miss rate of 5 MPKI would usually cost less, because the out-of-order back end overlaps data misses but has nothing to work on when instructions stop arriving.

Answer the misses add 0.1 CPI, making the core 30% slower.

Worked example

An 8-wide fetch loses one bubble cycle on every taken branch, and taken branches come every 8 instructions. What rate does it reach, and what without the bubble?

Show the solution
  1. With the bubble. Each run of 8 instructions takes one fetch cycle and one bubble: 8/(1+1)=4per cycle half the width.
  2. Without the bubble. It would deliver 8 per cycle.
  3. What that's worth. A zero-bubble BTB redirect is worth as much as doubling the fetch width here.

Answer 4 instructions a cycle with the bubble, and 8 without it.

Check

A 6-wide fetch stops at taken branches, which come every 5 instructions; each redirection costs 2 bubble cycle(s).

(a)

What fetch rate does it reach?

(b)

What fraction of the fetch slots carry instructions?

Check

A micro-op cache hits 0.8 of the time and delivers 6 µops a cycle; the decoders deliver 4.

(a)

What average rate does the front end reach?

Check

A program misses the instruction cache 5 times per thousand instructions, at 12 cycles each, on a core whose CPI is otherwise 0.5.

(a)

What CPI do the misses add?

(b)

What fraction of the time is the front end starving the core?

Check

Why does a micro-op cache save power as well as raising the delivery rate on an x86 core?

Check

Taken branches come every t instructions; fetch is w wide and loses b cycles per redirection. Treat ⌈t/w⌉ as t/w.

Step 1

How many cycles does each run between taken branches take?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Check

Write fetch_rate(runs, w, b): given a list of run lengths (instructions between taken branches), a fetch width w and b bubble cycles per redirection, return instructions per cycle, counting ⌈t/w⌉+b cycles per run.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why do instruction-cache misses usually hurt an out-of-order core more than data-cache misses of the same frequency?

Practice

Keep practicing

6 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.