Number of cycles needed to execute 100 instructions:

- For 100 instructions 20 instructions creates 2 stall cycle ( because they mention a
** pipeline processor has two branch** **delay slots**.) because of branch instruction.

So total no of stall cycle/instruction = 0.80*0 + 0.20*2 = 0.40 Stall/instruction

**Total time = 1 + 0.40 = 1.40 cycle/instruction .**

now for 100 instructions total time takes 1.40 * 100 = 140 ( this is without optimization)

so 140 is without optimization value,

2. With optimization ( 140 - 20 * 0.85- 20 * 0.2 ) = 119

In question it is given "**we assume that 20 percent of the instructions executed are branch instructions " **

here 20 is number of instructions out of 100 instructions

so 20* 0.85 as (*optimizing compiler can fill one of these slots 85 percent of the time - is given in question) ** *and 20 * 0.2 ( as given - **can fill the second slot only 20 percent of the time. ) ** and subtract that from 140, so it gives 119

see here

{140 -( 20 * 0.85) - (20* 0.2) } = 119

now to calculate percentage improvement in performance achieved by this optimization they use the formula :

(without optimization time / with optimization time ) * 100

that means {(140 / 119 ) - 1 * 100} = 17.64 %

Earlier performance was 1 and now it is 1.1764 ( 140/119 = 1.1764) so performance improvement by the optimization is 17.64%