CS 152 Computer Architecture and Engineering
CS252A Graduate Computer Architecture Lecture 7 - Memory III

Chris Fletcher
UC Berkeley, Spring 2026

Roadmap

$\text{AMAT} = \text{Hit time} + \text{Miss rate} \times \text{Miss penalty}$

TechniqueTargets
Victim cachesConflict misses, without hurting hit time
Way predictionSet-associative hit time
Early restart / critical word firstMiss penalty of long blocks
Non-blocking cachesBandwidth; hide miss penalty
PrefetchingCompulsory + capacity misses
Compiler optimizationsMiss rate, at zero hardware cost

Victim Caches (HP 7200)

CPU / RF L1 data cachedirect mapped Victim cache4 blocks, fully assoc. Unified L2 evicted hit: swap
  • Look up the direct-mapped L1 first (fast hit)
  • L1 miss → check the victim cache (VC)
    • VC hit: swap the VC line with L1's victim; no L2 access
    • VC miss: fetch from L2 into L1; L1 victim → VC; VC victim → L2
  • Direct-mapped hit time with associative conflict rate

Pseudo-associative caches: probe a primary index, then a re-hashed secondary slot on a miss.

Way-Predicting Caches

Check predicted way match HIT (fast) no match Check other ways SLOW HIT + update table MISS: fetch next level

Early Restart and Critical Word First

Long blocks save tag area but raise miss penalty. CPU asked for Word 2:

Early restart Word 0Word 1Word 2 →CPUWord 3 Critical word first Word 2 →CPUWord 3Word 0Word 1 arrival order →

Non-Blocking (Lockup-Free) Caches

Value of Hit Under Miss (SPEC92)

8 KB direct-mapped D$, 32 B blocks, 16-cycle miss. AMAT vs. outstanding misses allowed:

Outstanding misses0 (blocking)1264
Floating point0.680.520.340.26
Integer0.240.200.190.19

Check Your Understanding

1. Protocol: direct-mapped L1 + victim cache. An access misses L1 but hits the VC. What happens to the evicted L1 line?
The lines swap: the VC line moves into L1 and L1's evicted line takes its slot in the VC.
2. Workload: why does 1 → 64 outstanding misses cut AMAT a lot for FP code (0.52 → 0.26) but barely for integer code (0.20 → 0.19)?
FP loops issue many independent array accesses that overlap; integer code has pointer/control dependences that stall before misses can pile up.

Prefetching

Hardware Data Prefetching

SchemeRule
Prefetch-on-missMiss to b → prefetch b+1
One-block lookahead (OBL)Any access to b → prefetch b+1 (generalizes to N blocks)
Stridedb, b+N, b+2N → prefetch b+3N
Spatial memory streaming (SMS)Offsets a, b, c seen in a region of size R; touching a+R → prefetch b+R, c+R
Pointer-chasing (CDP, DMP)p, *p, **p → prefetch ***p, ****p

Software Prefetching

for (i = 0; i < N; i++) {
    prefetch(&a[i + P]);
    prefetch(&b[i + P]);
    SUM = SUM + a[i] * b[i];
}

Compiler Optimizations

Loop Interchange

x[i][j] stored row-major: x[i][0], x[i][1], … share a cache line

// Before: inner loop walks
// down a column (stride N)
for (j = 0; j < N; j++)
  for (i = 0; i < M; i++)
    x[i][j] = 2 * x[i][j];
// After: inner loop walks
// along a row (stride 1)
for (i = 0; i < M; i++)
  for (j = 0; j < N; j++)
    x[i][j] = 2 * x[i][j];

Loop Fusion

// Before: loop 1 writes all of
// a[], evicting early elements
// before loop 2 reads them
for (i = 0; i < N; i++)
  a[i] = b[i] * c[i];
for (i = 0; i < N; i++)
  d[i] = a[i] * c[i];
// After: a[i] and c[i] reused
// while still hot
for (i = 0; i < N; i++) {
  a[i] = b[i] * c[i];
  d[i] = a[i] * c[i];
}

Matrix Multiply with Cache Tiling

for (jj = 0; jj < N; jj = jj + B)
  for (kk = 0; kk < N; kk = kk + B)
    for (i = 0; i < N; i++)
      for (j = jj; j < min(jj + B, N); j++) {
        r = 0;
        for (k = kk; k < min(kk + B, N); k++)
          r = r + y[i][k] * z[k][j];
        x[i][j] = x[i][j] + r;
      }

Check Your Understanding

1. Concept: why is an OBL prefetcher with a stream buffer better than doubling the block size?
Doubling halves the number of lines (more conflicts) and wastes bandwidth on unused halves; OBL keeps small blocks and stages prefetches without polluting the cache.
2. Locality: which locality do loop interchange, loop fusion, and cache tiling each mainly improve?
Interchange: spatial. Fusion and tiling: temporal.