A Compiler designer is trying to decide between two code sequences for a compute
ID: 3791692 • Letter: A
Question
A Compiler designer is trying to decide between two code sequences for a computer. The hardware designer have supplied the following facts, there are 4 category instruction class, A, B, C and D, the CPI for each category of the instruction is given below. For a particular HLL statement, the compiler writer is considering two code sequences that requires the following instruction counts Which code sequence execute the most instruction? Which code sequence will be faster? What is the overall CPI for each sequence?Explanation / Answer
1.Which code executes the most instruction ?
Let's count the number of cycles needed to execute each code:
First code Sequence : No. of cycles = 2x1 + 1x2 + 2x3 +2x5 = 20 cycles.
Second code Sequence: No. of cycles = 4x1 + 1x2 + 2x3 +1x5 = 17 cycles.
Therefore the First code executes the most instruction .
2. Which code sequence will be faster ?
First code Sequence : No. of cycles = 2x1 + 1x2 + 2x3 +2x5 = 20 cycles.
Second code Sequence: No. of cycles = 4x1 + 1x2 + 2x3 +1x5 = 17 cycles.
Therefore the second code is faster because it requires less number of cycles to execute.
The ratio is (# cycles 1)/(# of cycles 2) = 20/17= 1.17
Therefore the second code 2 is faster than the first code by 1.17 times.
3. What is the overall CPI for each sequence?
CPI1= CPU_cycles1/ Instruction_count1= 20/6 = 3.33
CPI2= CPU_cycles2/ Instruction_count2= 17/8 = 2.125
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.