SIMD vectorization, in 16 keywords

Learn when one instruction can work on many values, how to get the compiler to do it, and why memory often stops it.

Your win today You can explain why a dot-product loop does not vectorize, restructure it with partial sums and a remainder loop, and judge with the memory-wall numbers on Vectorization p.52 whether SIMD will pay off. About 40 minutes.

Page numbers are the numbers printed on the slides (from slide 26 on, they are one higher than the PDF page).

1 · Scalar vs SIMD

SIMD single instruction, multiple data
A vectorized instruction applies one operation to a vector of data items at once; a scalar (SISD) instruction handles one item Vectorization pp.4–5. It is a CPU instruction-set extension on top of pipelining, superscalar and OoO execution Vectorization p.3.
SSE 128-bit registers
Intel's Streaming SIMD Extensions (1999) use 128-bit registers that hold four 32-bit values, and one operation works on all four Vectorization p.14. Register width ÷ element width = number of lanes.
AVX2 / AVX-512 16 × 256-bit / 32 × 512-bit
AVX2 has 16 vector registers of 256 bits; AVX-512 has 32 of 512 bits Vectorization p.15. Wider registers mean more lanes per instruction: 8 or 16 floats.
NEON / SVE Arm SIMD
Arm's SIMD extensions are NEON and the Scalable Vector Extension; x86 has MMX, SSE and AVX Vectorization p.13. Intrinsics written for one family do not run on the other.

How many 32-bit floats fit in one AVX2 register?

AVX2 registers are 256 bits; 256 / 32 = 8. Four is SSE (128 bits), sixteen is AVX-512 Vectorization pp.14–15.

Which instruction class can move data from a SIMD register straight to memory, bypassing the CPU cache?

Cache control moves data directly from SIMD registers to memory, bypassing the cache Vectorization p.17.

2 · Getting SIMD into your code

auto-vectorization choice 1
The compiler finds loops whose body it can rewrite as vector operations, such as c[i] = a[i] + b[i] Vectorization pp.18–19. It works only for "simple loops", which are rare in most applications Vectorization p.19.
pointer aliasing X, Y, Z may overlap
If pointers might point to the same address, the compiler must assume the additions happen one after the other and will not vectorize Vectorization p.20. It is the most common reason a simple-looking loop stays scalar.
restrict compiler hint
The restrict keyword tells the compiler that the arrays are distinct memory locations Vectorization p.22. Not in the C++ standard, but supported by most compilers Vectorization p.22.
pragma ivdep compiler hint
Tells the compiler to ignore loop dependencies for the vectors in the loop Vectorization p.23. The compiler no longer checks: correctness is up to you Vectorization p.23.
intrinsics explicit vectorization
Functions such as _mm256_load_ps and _mm256_mul_ps let you load SIMD registers and run vector instructions yourself Vectorization pp.24, 26. Full control, but potentially not portable Vectorization p.24.

Why is void add(int *X, int *Y, int *Z) with Z[i] = X[i] + Y[i] not auto-vectorized?

Possible aliasing forces the compiler to treat the additions as sequential Vectorization p.20.

You add #pragma ivdep to a loop that really has a dependency. What happens?

ivdep tells the compiler to ignore dependencies; making sure that is correct is up to the developer Vectorization p.23.

3 · Dependencies decide

data dependency RAW · WAR
A step is vectorizable only if it consists of independent steps that can run in parallel without data hazards such as read-after-write and write-after-read Vectorization p.30. "The keyword is dependency" Vectorization p.30.
loop-carried dependency sum = sum + X[i]·Y[i]
Each iteration needs the sum from the previous one, so the dot product cannot be vectorized directly; fix it with independent partial sums, then reduce them to one value Vectorization pp.38–40. The reduction itself fits in a single SIMD operation Vectorization p.40.
remainder loop n not divisible by width
Run the vector loop up to split_point = n − (n % 4) and finish the rest with a scalar loop that runs fewer than 4 times Vectorization pp.41–43. Without it, the vector loop would read past the end of the arrays.

What blocks direct vectorization of sum = sum + X[i] * Y[i]?

Every iteration reads the sum written by the previous one Vectorization p.38.

With 4 partial sums and n = 1 003, how many iterations does the scalar remainder loop run?

split_point = 1 003 − (1 003 % 4) = 1 000, so the remainder loop runs i = 1 000, 1 001, 1 002 Vectorization p.43.

4 · Hard cases: indirect access and branches

sparse SAXPY X[K[i]] = a·X[K[i]] + Y[M[i]]
The indices come from arrays K and M, so two iterations might write the same element of X Vectorization pp.33–34. It is still vectorizable if you can guarantee the compiler that there are no collisions Vectorization p.34.
predication masks · blend
Replace a branch inside the loop by computing a 0/1 condition and using it arithmetically, e.g. X[i] = ((X[i] < 50) + 1) * X[i] Vectorization p.47. With SIMD, a vector compare produces a mask, and AND, blend or masked load/store apply it per lane Vectorization pp.49–50.

The loop if (X[i] < 50) X[i] = 2*X[i]; does not vectorize. Why?

The branching instruction prevents vectorization; the fix is predication Vectorization p.46.

In explicit SIMD, what does a vector comparison such as xs > condition produce?

The comparison produces a mask; AND-ing xs with it keeps the value or gives 0 in each lane Vectorization p.49.

5 · Where SIMD pays off

columnar scan filter → bit vector
Scanning and filtering a column with a simple comparison is a good match for SIMD: scan the column, produce a bit vector Vectorization p.28. Dense input gave 8.4×, sparse input only 2.7×, and the whole TPC-H Q6 query 1.4×, because other operations also take time Vectorization p.28.
memory wall FLOP/byte
Peak SIMD throughput is only reached if the data is in cache; otherwise the computational intensity (FLOP per byte) must exceed what DRAM bandwidth can deliver Vectorization p.52. In 2026, DRAM is ~680× too slow to feed a Ryzen 9 9950X at peak (2010: ~38×) Vectorization p.52.

A SIMD filter is 8.4× faster on dense input, but the full TPC-H Q6 query only 1.4×. Why?

End-to-end results also depend on the other operations in the query Vectorization p.28.

When is SIMD on a CPU of limited use, according to the summary?

"Usefulness of SIMD limited on CPUs if data doesn't fit in cache or computational intensity is very low" Vectorization p.53.

6 · Use the keywords: the exam question

Vectorize for (i=0; i<n; i++) sum = sum + X[i] * Y[i]; for AVX2 (8 floats per register) with n = 1 003. Why doesn't it vectorize as written, and how do you restructure it? Vectorization pp.37–43 Try it on paper first, then open each step.

Step 1: Find the blocker

sum is read and written every iteration: a loop-carried dependency Vectorization p.38.

Step 2: Break the dependency

Keep 8 independent partial sums, one per lane; the inner loop over j = 0..7 has no dependency and maps to one vector multiply and add per step Vectorization p.39.

Step 3: Handle the remainder

split_point = 1 003 − (1 003 % 8) = 1 000. The vector loop runs 1 000 / 8 = 125 times; a scalar loop handles i = 1 000…1 002 (3 elements) Vectorization p.43.

Step 4: Reduce

Add the 8 partial sums into one value; this fits in a single SIMD reduce operation Vectorization p.40.

Step 5: Check if it pays

A dot product does 2 FLOPs per 8 bytes read: if X and Y come from DRAM, the memory wall, not the SIMD width, sets the speed Vectorization pp.52–53.

Exam answer pattern Name the dependency → partial sums → split point and remainder → reduction → memory-bound or compute-bound?

7 · Keyword recall drill

SIMDA vectorized instruction applies one operation to a vector of data items at once; a scalar (SISD) instruction handles one item.
SSEIntel's Streaming SIMD Extensions (1999) use 128-bit registers that hold four 32-bit values, and one operation works on all four.
AVX2 / AVX-512AVX2 has 16 vector registers of 256 bits; AVX-512 has 32 of 512 bits.
NEON / SVEArm's SIMD extensions are NEON and the Scalable Vector Extension; x86 has MMX, SSE and AVX.
auto-vectorizationThe compiler finds loops whose body it can rewrite as vector operations, such as c[i] = a[i] + b[i].
pointer aliasingIf pointers might point to the same address, the compiler must assume the additions happen one after the other and will not vectorize.
restrictThe restrict keyword tells the compiler that the arrays are distinct memory locations.
pragma ivdepTells the compiler to ignore loop dependencies for the vectors in the loop.
intrinsicsFunctions such as _mm256_load_ps and _mm256_mul_ps let you load SIMD registers and run vector instructions yourself.
data dependencyA step is vectorizable only if it consists of independent steps that can run in parallel without data hazards such as read-after-write and write-after-read.
loop-carried dependencyEach iteration needs the sum from the previous one, so the dot product cannot be vectorized directly; fix it with independent partial sums, then reduce them to one value.
remainder loopRun the vector loop up to split_point = n − (n % 4) and finish the rest with a scalar loop that runs fewer than 4 times.
sparse SAXPYThe indices come from arrays K and M, so two iterations might write the same element of X.
predicationReplace a branch inside the loop by computing a 0/1 condition and using it arithmetically, e.g.
columnar scanScanning and filtering a column with a simple comparison is a good match for SIMD: scan the column, produce a bit vector.
memory wallPeak SIMD throughput is only reached if the data is in cache; otherwise the computational intensity (FLOP per byte) must exceed what DRAM bandwidth can deliver.

8 · True / False

T / FSSE registers are 128 bits wide and hold four 32-bit values.

True Vectorization p.14.

T / FAVX-512 provides 16 vector registers of 512 bits.

False. AVX-512 has 32 registers of 512 bits; AVX2 has 16 of 256 bits Vectorization p.15.

T / FAuto-vectorization handles most loops in real applications.

False. It works for simple loops only, which are rare Vectorization p.19.

T / FThe restrict keyword is part of the C++ standard.

False. It is not standard C++ but works in most compilers Vectorization p.22.

T / FWith pragma ivdep, the compiler proves the loop has no dependencies before vectorizing.

False. It ignores them; correctness is up to the developer Vectorization p.23.

T / FCode written with intrinsics is portable across all CPU families.

False. Intrinsics are potentially not portable Vectorization p.24.

T / FA loop-carried dependency on an accumulator prevents direct vectorization.

True Vectorization p.38.

T / FSparse SAXPY can still be vectorized if the indices are guaranteed not to collide.

True Vectorization p.34.

T / FPredication turns a branch into arithmetic on a 0/1 condition.

True Vectorization p.47.

T / FPeak SIMD utilization is only achievable when the data is in cache.

True Vectorization p.52.

9 · What is …?

What isthe difference between SIMD and SISD

Show answer

SISD processes one data item per instruction; SIMD performs the same operation on multiple values with one instruction Vectorization p.5.

What isthe three ways to use SIMD extensions

Show answer

Automatic vectorization by the compiler, compiler hints (restrict, pragmas), and explicit vectorization with intrinsics Vectorization p.18.

What isa read-after-write (RAW) hazard

Show answer

A later step reads a value that an earlier step writes, so the two cannot run in parallel Vectorization p.30.

What isbroadcasting in the explicit SAXPY

Show answer

Setting all 8 floats of a vector register to the scalar a, so it can be multiplied with 8 elements of X at once Vectorization p.36.

What is_mm256_blendv_epi8

Show answer

An intrinsic that combines the values of two vectors, choosing per element according to a mask vector Vectorization p.50.

What ismasked load and store

Show answer

_mm256_maskload_epi32 / _mm256_maskstore_epi32 load or store a SIMD block and apply a mask in the same step Vectorization p.50.

What isthe SIMD instruction classes

Show answer

Data movement (load/store), arithmetic (ADD, MUL, SQRT, MIN, MAX…), bitwise, comparison and shuffle, conversion, and cache control Vectorization pp.16–17.

What isthe slides' recommended choice for most developers

Show answer

Use libraries for your domain; use intrinsics only for non-trivial code when you know what you're doing; otherwise write compiler-friendly code with pragmas Vectorization p.53.

10 · Calculations

ComputeHow many lanes does one register give for 32-bit floats in SSE, AVX2 and AVX-512? How many 16-bit integers fit in one AVX-512 register?

Show solution

Lanes = register bits ÷ element bits. SSE: 128 / 32 = 4; AVX2: 256 / 32 = 8; AVX-512: 512 / 32 = 16 Vectorization pp.14–15. 16-bit integers in AVX-512: 512 / 16 = 32.

ComputeThe demo multiplies two float arrays of n = 1 000 000 elements (c[i] = a[i] * b[i]). How many multiply instructions does the scalar loop execute, and how many does the AVX2 loop with i += 8 execute?

Show solution

Scalar: one per element, 1 000 000. AVX2: one _mm256_mul_ps per 8 elements, 1 000 000 / 8 = 125 000, i.e. 8× fewer Vectorization p.26.

ComputeA dot product with 4 partial sums runs on n = 1 003 elements. Compute split_point, the number of vector iterations and the number of scalar remainder iterations.

Show solution

split_point = 1 003 − (1 003 % 4) = 1 003 − 3 = 1 000. Vector iterations: 1 000 / 4 = 250. Remainder: 3 scalar iterations (i = 1 000, 1 001, 1 002) Vectorization p.43.

ComputeUsing the memory-wall table, how many FLOPs per byte must a kernel perform so that DRAM bandwidth does not limit it, in 2010 (102 GFLOP/s, 32 GB/s) and in 2026 (~5 100 GFLOP/s, ~90 GB/s)?

Show solution

Needed intensity = peak FLOP/s ÷ bandwidth. 2010: 102 / 32 ≈ 3.2 FLOP/byte. 2026: 5 100 / 90 ≈ 57 FLOP/byte Vectorization p.52. The bar rose ~18× in 16 years.

ComputeSingle-precision SAXPY (X[i] = a·X[i] + Y[i]) reads X[i] and Y[i] and writes X[i], 4 bytes each, and does 2 FLOPs per element. What is its intensity, and is it compute-bound or memory-bound on the 2026 CPU?

Show solution

Bytes per element: 3 × 4 = 12. Intensity = 2 / 12 ≈ 0.17 FLOP/byte, far below the ~57 needed Vectorization pp.32, 52. It is memory-bound: on data from DRAM, wider SIMD barely helps Vectorization p.53.

11 · Exam-style questions (written)

  1. Explain. Explain why the compiler refuses to auto-vectorize Z[i] = X[i] + Y[i] over three pointer arguments, and give two ways to make it vectorize Vectorization pp.20–23.
  2. Compare. Compare auto-vectorization, compiler hints and intrinsics in terms of effort, control, correctness risk and portability Vectorization pp.18–24.
  3. Argue. Should you hand-vectorize a filter over a 100 GB column that lives in DRAM? Argue with the memory-wall numbers Vectorization p.52.
  4. Transfer. Sketch how to vectorize if (x[i] > t) y[i] = 3*x[i]; else y[i] = x[i]; with masks, and name the instructions you would use Vectorization pp.47–50.

Bring your answers to the chat and I'll grade them the way an examiner would.

Read next

Primary source: the deck (../lectures/Lecture_05_Vectorization.pdf, slides 30–50 are the core). The slides recommend the Intel Intrinsics Guide (https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html) and the masking chapter of Algorithmica (https://en.algorithmica.org/hpc/simd/masking/) Vectorization p.50. Review with the cheat sheet.