4.1.24 · D3Computer Architecture (Deep)

Worked examples — SIMD — vector instructions, SSE - AVX

2,373 words11 min readBack to topic

The scenario matrix

Every SIMD sizing/speedup question is one of these case-classes. We will cover all of them.

Cell Case class What makes it tricky Covered by
A Clean division (len is a multiple of lanes) none — baseline Ex 1
B Ugly remainder (len not a multiple of lanes) tail loop, len % lanes Ex 2
C Different element widths (f64, int8, int16) lane count changes with element size Ex 3
D Degenerate inputs (len = 0, len < lanes) main loop runs zero times Ex 4
E Amdahl ceiling (partly vectorizable) speedup ≪ lanes Ex 5
F Memory-bandwidth wall (limiting behaviour) roofline caps you below lanes× Ex 6
G Horizontal reduction (cross-lane fold) the log-fold, off-by-one lane math Ex 7
H Real-world word problem pick the width, translate to lanes Ex 8
I Exam twist: float non-associativity SIMD sum ≠ scalar sum bit-for-bit Ex 9

Two numbers drive almost everything, so define them once and reuse:

Figure — SIMD — vector instructions, SSE - AVX

Cell A — clean division


Cell B — ugly remainder


Cell C — different element widths


Cell D — degenerate inputs


Cell E — Amdahl ceiling

Figure — SIMD — vector instructions, SSE - AVX

Cell F — memory-bandwidth wall (limiting behaviour)


Cell G — horizontal reduction fold

Figure — SIMD — vector instructions, SSE - AVX

Cell H — real-world word problem


Cell I — exam twist: float non-associativity


Active recall

Recall Length 1003 f32 on AVX: vector iters and tail?

vector iterations, scalar tail elements.

Recall Why does SIMD do nothing in Ex 6?

Both scalar and AVX are already memory-bandwidth bound (intensity flop/byte), so widening the ALU cannot help — you run at (compute, memory) = memory ceiling.

Recall Fold steps to reduce 8 lanes to 1?

pairwise steps: .

Recall 90% vectorizable, 8 lanes — total speedup?

, not 8×.