Custom Search

CPI

How many cycles are required for a program to run?

Could we assume that N cycles will perform N instructions? No, we couldn't because
different instructions take different amounts of time on different machines.

In general

  • Multiplication takes more time than addition
  • Floating point operations take longer than integer ones
  • Accessing memory takes more time than accessing registers

Now for some computer abbreviations and jargon that you need to understand and know:

CPI (Cycle per Instruction)

CPI tells you the average cycles per instruction for a program.

Instruction Count (Ic) is the number of machine instructions executed.

CPIiis the number of cycles required for instruction type i

Ii is the number of executed instructions of type i

Now, this equation looks daunting... but it isn't so bad when you know what it means.

(CPIi x Ii) gives you the total number of cycles for one type of instruction as you have multiplied the number of that instruction type by the average time to carry out that instruction type.

However as different instructions take different numbers of cycles to perform them... and you do not have an equal number of each type of instruction, you need to add up that value for each type. That is where the 'sigma' term comes in!

The sigma term uses the Greek capital letter for 'S' to denote 'sum of'. It means you have to sum all of the terms in the bracket (CPIi x Ii) taking i from value 1 to n.

In other words:

(CPIi x Ii) = (CPI1 x I1) + (CPI2 x I2) .......... + (CPIn-1 x In-1) + (CPIn x In)

After summing them all you have to divide your sum total by Ic - the instruction count, the number of instructions carried out (of all types). That will then give you a more accurate picture of the average number of cycles for an instruction.

What is the real time for a program to run?

CPU execution time T

This is the time needed by a CPU to fully execute a program. This is measured in seconds.

T = Ic x CPI x

Another method for calculating CPI

  • calculate CPI for each individual instruction (add, sub, and, etc.)
  • calculate frequency of each individual instruction
  • multiply these two for each instruction and add them up to get final CPI (the weighted sum)

Example: From the data below calculate

(a) the CPI and

(b) the MIPS rate for the processor - number of instructions = 400 x 106.

Instruction Type
CPI
Instruction Mix
ALU
1
60%
Load/store with cache hit
2
18%
Branch
4
12%
Memory reference with cache miss
8
10%

Average CPI = (1 x 0.6) + (2 x 0.18) + (4 x 0.12) + (8 x 0.1) = 2.24

MIPS rate = instruction count/(CPU execution time x 106)= Ic/(T x 106)

MIPS rate = (400 x 106) / (2.24 x 106) ≈ 178 (round down)

MIPS rate is useful for comparing performance between similar processors but machines with different instruction sets and programs with different instruction mixes cannot be easily differentiated between by using it.

MFLOPS is useful for comparing performance if the processor has to perform a lot of computations with floating-point numbers.