Course: Computer Architectures

Lecture: Lecture 07 - Instruction-Level Parallelism

Loop-level parallelism

The lecture uses:

for (int i = 0; i < N; ++i)
    x[i] = x[i] + y[i];

For ordinary nonoverlapping arrays, an iteration does not need another iteration’s result. Independent iterations offer more scheduling opportunities than a small basic block.

Assumption: Array aliasing can invalidate independence. For example, if y[i] refers to x[i-1], one iteration can consume the preceding iteration’s new value. Also, a recurrence such as x[i] = x[i-1] + y[i] is a true loop-carried dependence. Unrolling does not remove it.

Four-way unrolling

Unrolling explicitly replicates the loop body. The following is an explanatory C version of slides 15-17 with a remainder loop added:

int i = 0;
for (; i + 3 < N; i += 4) {
    x[i]     = x[i]     + y[i];
    x[i + 1] = x[i + 1] + y[i + 1];
    x[i + 2] = x[i + 2] + y[i + 2];
    x[i + 3] = x[i + 3] + y[i + 3];
}
for (; i < N; ++i)
    x[i] = x[i] + y[i];

Assume valid array bounds and an ordinary nonnegative loop bound that does not overflow the shown index expressions.

For N=10, the main loop handles indices 0-3 and 4-7. The tail handles 8 and 9. Omitting the tail loses elements; executing a full third group accesses beyond the array.

Why it can help

One loop-control sequence covers four elements, reducing relative branch/index overhead. The compiler sees more loads and arithmetic operations that can be interleaved to hide latency, often using different temporary registers.

Replication alone does not guarantee a faster pipeline schedule; instructions must still be scheduled legally and hardware must have capacity to exploit the overlap.

Costs

Code size increases. More simultaneous temporaries can raise register pressure and cause spills. Larger code can increase instruction-cache demand. The latter two are study clarifications beyond slide 18’s stated code-size cost.

SIMD and vector processing

SIMD applies an instruction to multiple data elements. Slides 19-21 summarize vector array addition as load x, load y, add, and store.

TechniqueWhat changes?
UnrollingMore scalar body instructions are written explicitly
SIMD/vectorizationInstructions operate on groups of elements

Both can be combined. GPUs are another setting for data-parallel execution; the slide’s SIMD grouping is an introductory abstraction rather than a complete account of GPU execution.

Timing qualification

Slide 21 assumes each vector operation takes the same time as its scalar counterpart. Keep that as a simplified lecture assumption. Actual time depends on vector length, lanes, execution throughput, memory bandwidth, and startup overhead. Four conceptual operations for 1,000 elements do not imply four clock cycles.

Real machines may process a long array in chunks. RISC-V vector code uses a configured active vector length and strip-mining to cover the remaining elements; the whole array need not fit in one vector operation. Official RISC-V vector specification.

LLVM likewise describes runtime alias checks and scalar remainder loops when required. LLVM vectorizer documentation.

Instruction-Level Parallelism, Instruction Dependencies, Register Renaming, Memory Addressing, Branches.

E. Sanchez, Instruction Level Parallelism, ASE 2026/27, slides 13-21. PDF: Instruction Level Parallelism.pdf. Tail handling, recurrence/alias examples, and practical limitations are labeled study additions.

Measured lab applications

The normalization lab compares scheduling with factor-two unrolling and shows why lower elapsed time can accompany slightly higher CPI. Lab 03 - Normalization Scheduling and Unrolling

The AdaGrad lab compares factor-two and factor-four unrolling with independent latency experiments; use the lab’s own settings rather than the lecture’s illustrative numbers. Lab 04 - AdaGrad Scheduling and Unrolling