Skip to content
BetterDL

CPI

Also called: cycles per instruction, average CPI, weighted CPI, clocks per instruction

Cycles per instruction: the total clock cycles a program takes divided by the number of instructions it executes.

CPI stands for cycles per instruction. It's the average number of clock cycles each executed instruction takes:

CPI = total clock cycles ÷ instructions executed

When instruction types take different numbers of cycles, CPI is a weighted average. Multiply each type's cycle count by its fraction of the instructions executed, then add.

On Tiny8, LOAD, STORE, ADD and SUB take 6 cycles each, and JMP, JZ and HALT take 5. So any Tiny8 program has a CPI between 5 and 6, closer to 6 when it's mostly memory instructions.

CPI is one of three factors in cpu execution time:

time = instructions × CPI × clock period

A single cycle processor has CPI = 1 by definition, but a long clock period. A multi cycle processor has CPI above 1 and a short period. Neither number alone says which is faster.

Worked examples

Example

Weighted CPI for a mix

A program's executed instructions are 50 % arithmetic (4 cycles), 30 % loads (5 cycles) and 20 % branches (3 cycles).

  1. 1.

    Arithmetic: 0.5 × 4 = 2.0.

  2. 2.

    Loads: 0.3 × 5 = 1.5.

  3. 3.

    Branches: 0.2 × 3 = 0.6.

  4. 4.

    CPI = 2.0 + 1.5 + 0.6 = 4.1.

Example

CPI of a Tiny8 run

A Tiny8 run executes 6 memory instructions, 3 jumps and a HALT.

  1. 1.

    Cycles: 6 × 6 + 3 × 5 + 5 = 36 + 15 + 5 = 56.

  2. 2.

    Instructions: 6 + 3 + 1 = 10.

  3. 3.

    CPI = 56 ÷ 10 = 5.6.

Common mistakes

  • Averaging cycle counts without weights. A common type counts for more than a rare one.

  • Counting instructions in the listing instead of instructions executed. A loop body counts once per pass.

Practice CPI

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

CPI is taught in Basic CPU / Computer Architecture.