CS/COE 1541 Term 2174 Quiz 1: (Solutions)
CS/COE 1541 Term 2174 Quiz 1: (Solutions)
CS/COE 1541 Term 2174 Quiz 1: (Solutions)
You could stall, letting one instruction go first; you could add more hardware so that there's enough
for all the instructions to use simultaneously.
You could stall, waiting for the previous instruction to finish executing; you could add forwarding
hardware to let the second instruction get the data it needs earlier.
They can be worse because while structural and data hazards only stall one instruction, control hazards
could cause you to flush multiple instructions (especially when the pipeline is deeper).
What your example code looks like can vary, but as long as it makes sense, it's fine.
1
We added early branch decision and a branch predictor to our little MIPS CPU. We want to see if it
was worth the effort. We have a test suite of programs that we'll use to compare the performance of
the old and new CPUs. The branch instructions' average CPI (in the test suite) and clock cycle times
of the two CPUs are summarized below:
Here's our test suite's instruction mix, and the average CPIs of the other instruction classes.
7. First you need to calculate the overall average CPI of the whole test suite for both CPUs. Please
circle/box your answer.
a. [2] What is the overall average CPI of the test suite for the old CPU? Show your math.
(3 x 60%) + (6 x 10%) + (5 x 10%) + (6 x 20%) = 1.8 + 0.6 + 0.5 + 1.2 = 4.1 cycles/instruction
b. [2] What is the overall average CPI of the test suite for the new CPU? Show your math.
(3 x 60%) + (6 x 10%) + (5 x 10%) + (3 x 20%) = 1.8 + 0.6 + 0.5 + 0.6 = 3.5 cycles/instruction
8. Now you can calculate the total execution time of the test suite for both CPUs. The test suite runs
8 x 108 instructions. Please circle/box your answer. It should be in seconds.
a. [2] What is the total execution time of the test suite for the old CPU? Show your math.
(8 x 108) x (4 x 10-8) x 4.1 = 131.2 seconds
b. [2] What is the total execution time of the test suite for the new CPU? Show your math.
(8 x 108) x (5 x 10-8) x 3.5 = 140 seconds
9. [2] Was adding the branch predictor a good idea? If yes, explain why. If no, explain what would
have to change to make it worthwhile.
No, not in this case. The branch predictor made the cycle length too long, and so performance
decreased even though the CPI was improved. In order for it to be worthwhile, the cycle length
would have to be improved. (You didn't need to show numbers, but if you did, the cycle length
would have to be about 4.5x108 s or shorter.)