CS 152 Computer Architecture and Engineering
CS252A Graduate Computer Architecture Lecture 18 - Vector Processors

Chris Fletcher
UC Berkeley, Spring 2026

Supercomputer Applications

Vector Programming Model

  • Scalar unit (x0–x31) + vector extension
  • Vector registers v0–v31, each VLMAX elements
    • Cray-1: 8 × 64 elements, plus mask and length
  • Vector length vl: elements 0 … vl−1
  • vadd v3, v1, v2: elementwise
  • vld v1, (x1) unit stride; vls v1, (x1), x2 stride x2
. [0][1][2]…[VLMAX-1] v1 v2 v3 = v1 + v2 vl elements

Vector Code Example

for (i = 0; i < 64; i++) C[i] = A[i] + B[i];

Scalar: 9-instruction loop × 64

      li     x4, 64
loop: fld    f1, 0(x1)
      fld    f2, 0(x2)
      fadd.d f3, f1, f2
      fsd    f3, 0(x3)
      addi   x1, x1, 8
      addi   x2, x2, 8
      addi   x3, x3, 8
      subi   x4, x4, 1
      bnez   x4, loop

1 + 64 × 9 = 577 instructions

Vector

li     x4, 64
vsetvl x4
vld    v1, (x1)
vld    v2, (x2)
vadd   v3, v1, v2
vst    v3, (x3)

6 instructions

Vector Instruction Set Advantages

Vector Arithmetic Execution and Lanes

  • Elements are independent → deep pipelines (e.g., 6-stage multiply) with no hazard or bypass logic
  • Lanes: split the register file across parallel units
    • Element i lives in lane i mod #lanes
    • Each lane has its own ALU and memory port
    • No cross-lane wiring for arithmetic
    • T0 vector microprocessor (1995): 8 lanes
Lane 0Lane 1Lane 2Lane 3 048… 159… 2610… 3711… ALUALUALUALU memory subsystem

Vector Instruction Parallelism

LoadMulAdd vld 1vld 2vld 3vmul 1vmul 2vmul 3vadd 1vadd 2vadd 3 time →

Vector Chaining

vld  v1
vmul v3, v1, v2
vadd v5, v3, v4

Interleaved Vector Memory System

0123456789ABCDEF

Vector Registers vs. Memory-Memory

Check Your Understanding

1. 4 lanes, 64-element registers. Which elements of v1 are in lane 2, and how many cycles does a vector add take?
Elements 2, 6, 10, …, 62 (≡ 2 mod 4). 64 / 4 = 16 cycles.
2. What is vector chaining, and how does it speed up vld → vmul → vadd?
Vector bypassing: each element is forwarded to the dependent unit as soon as it's produced, so the three instructions overlap instead of waiting for whole vectors.

Automatic Code Vectorization

Vector Stripmining

    andi x1, xN, 63   # N mod 64
    vsetvl x1         # remainder first
loop:
    vld  v1, (xA)
    slli x2, x1, 3    # bytes
    add  xA, xA, x2
    vld  v2, (xB)
    add  xB, xB, x2
    vadd v3, v1, v2
    vst  v3, (xC)
    add  xC, xC, x2
    sub  xN, xN, x1
    li   x1, 64
    vsetvl x1         # full length
    bgtz xN, loop
  • Registers hold VLMAX = 64 elements; loops have arbitrary N
  • Do the N mod 64 remainder strip first (0 elements if N is a multiple of 64)
  • Every later pass runs at full vl = 64

Vector Conditional Execution

for (i = 0; i < N; i++)
  if (A[i] > 0) A[i] = B[i];
cvm            # mask all 1s
vld vA, (xA)
vgt vA, f0     # mask = A[i] > 0
vld vA, (xB)   # only where mask
vst vA, (xA)   # only where mask
  • Mask register: 1 bit per element; masked-off elements become NOPs
  • Simple: run all elements, gate write enable with M[i]
  • Density-time: scan the mask, execute only M[i] = 1
  • Compress: pack unmasked elements to the bottom; popcount = new length
  • Expand: the inverse, back to original positions

Vector Reductions

sum[0:VL-1] = 0;                    // VL partial sums
for (i = 0; i < N; i += VL)         // stripmine
    sum[0:VL-1] += A[i : i+VL-1];   // independent vector add

do {
    VL = VL / 2;                    // halve
    sum[0:VL-1] += sum[VL : 2*VL-1];
} while (VL > 1);

Vector Scatter/Gather

A[i] = B[i] + C[D[i]];

vld  vD, (xD)       # load index array D
vlx  vC, (xC), vD   # gather: vC[i] = Mem[xC + vD[i]]
vld  vB, (xB)
vadd vA, vB, vC
vst  vA, (xA)

Packed SIMD vs. Vector

Check Your Understanding

1. Compress A[0..7] with mask M = 10110010 (M[7] … M[0]). Which elements, and what new length?
A[1], A[4], A[5], A[7]; new length = popcount = 4.
2. Give two reasons true vector ISAs scale better than fixed-width packed SIMD.
A vector length register (same binary across widths, clean stripmining), and strided/scatter-gather access with long registers that keep units busy without superscalar dispatch or unrolling.