– Unofficial Answers Tutorial 2

advertisement
Tutorial 2 – Unofficial Answers
Prepared by: Colin Tan ctank@comp.nus.edu.sg
Most of this tutorial is just straight-forward application of the CPI formulae, so I’ll
just skip through most of the questions and head straight for the difficult ones.
From Tutorial 1 we recall the CPI formula:
CPI 
f
fA
f
f
CPI A  B CPI B  C CPI C  D CPI D
NP
NP
NP
NP
EQ1
Here fx is the number of instructions in class x, CPIx is the average CPI of all
instructions in class x, and Np is the total number of instructions in the program.
Rewriting fx/Np as Rx, we have:
CPI = RACPIA + RBCPIB+RCCPIC+RDCPID
EQ2
Here Rx is the “percentage” or the “frequency” of instructions that come from class x
for this particular program. Trivially, we can re-write EQ2 as:
CPI 
R A N P CPI A  RB N P CPI B  RC N P CPI C  RD N P CPI D
NP
EQ3
We’ll set aside EQ3 for a while and look at it again later.
Now we’ll look at the harder topics in this tutorial:
Question 2-21
In this question, the MBASE machine of 2-18 is used together with a compiler crafted
by the finest compiler writers in the world (I hate the phrase “world-class”, so it’s not
going to appear anywhere here!). The new compiler reduces the number of class A
instructions by 10%, class B by 10%, class C by 15% and class D by 5%. Table 1
below shows the new distributions together with the class CPIs (note that in this table
I have divided all frequency percentages by 100% for convenience):
Class
A
B
C
D
Total
CPI
2
3
3
5
N/A
Frequency
0.4
0.25
0.25
0.1
1.0
Table 1 – CPI, instruction frequency for MBASE and Mcomp
Page-1
New Frequency
0.9*0.4 = 0.36
0.9*0.25 = 0.225
0.85*0.25=0.2125
0.95*0.1=0.095
0.8925
The overall CPI for Mcomp is obviously:
0.36*2 + 0.225*3 + 0.2125*3 + 0.095*5 = 2.5075
This answer is obvious, but wrong.
The reason why is that the frequencies of Mcomp do not add up to 100% (i.e. 1.0)!
That is, the total number of instructions generated by Mcomp is 0.8925Np and not Np,
where Np is the total number of instructions generated on MBASE using the old
compiler. The total number of cycles used by the instructions would be:
Total_cycles = 0.36Np x 2 + 0.225Np x 3 + 0.2125Np x 3 + 0.095Np x 5
To get the CPI, we must divide by the total number of instructions. It is important to
remember that the total number of instructions is no longer Np since the new
frequencies do not add to 100%. The new total number of instructions is now
0.8925Np.
Therefore the CPI (total_cycles/number_of_instructions) is:
(0.36Np x 2 + 0.225Np x 3 + 0.2125Np x 3 + 0.095Np x 5)/0.8925Np
Cancel away Np and we’re left with:
CPI
= (0.36x2 + 0.225x3 + 0.2125x3 + 0.095x5)/0.8925
= 2.8095
In general, if the question includes a change in instruction frequencies, then it is
important to check if the new frequencies add up to 1.0. If it adds up to any number
other than 1.0, then the overall CPI computed the usual way must be divided by this
number, as shown in this case. THIS IS VERY IMPORTANT!
Question 2-22
How much faster is Mcomp over MBASE?
This question is quite easy to do, except that you must remember that for the Mcomp
machine the instruction count is 0.8925Np and not Np. The CPI for MBASE is 2.8,
and was computed in question 2-18.
Tmbase= (Np x 2.8)/(500 x 106)
Tmcomp = (0.8925Np x 2.8095)/(500 x 106)
Speedup = Tmcomp/Tmbase = 2.8/2.5 = 1.12x
Page-2
Question A-2
Most of this question is straightforward except for part [c], so we’ll tackle only this
part.
The MBASE machine has these characteristics:
Class
A
B
C
D
CPI
1
2
3
4
Frequency
0.1
0.2
0.3
0.4
As we can see from this table, instructions in some classes (e.g. A) are very fast, and
require, on average, only 1 clock cycle to complete. Instructions in other classes (e.g.
D), are slow, and require 4 cycles to complete.
The only way to achieve the lower bound on overall CPI is to force all instructions in
a program to come only from the fastest class. This is because we will not obtain the
lower bound as long as any instruction comes from any class other than class A. This
table will give us the lower bound on the CPI:
Class
A
B
C
D
Overall CPI
CPI
1
2
3
4
Frequency
1.0
0.0
0.0
0.0
= 1.0 x 1 + 0.0 x 2 + 0.0 x 3 + 0.0 x 4
= 1.0
Conversely, to obtain the upper bound, we must force all instructions to come from
the slowest class D:
Class
A
B
C
D
Overall CPI
CPI
1
2
3
4
Frequency
0.0
0.0
0.0
1.0
= 0.0 x 1 + 0.0 x 2 + 0.0 x 3 + 1.0 x 4
= 4.0
In general, the lower CPI bound is given by the smallest class CPI, while the upper
bound is given by the largest class CPI.
Page-3
Note that these figures are the lower and upper bounds on the CPI. In practice, these
figures are unlikely to ever be achieved, since to do anything useful we would need a
mix of instructions across all the classes.
Page-4
Download