in CO and Architecture edited by
752 views
11 votes
11 votes

Assume an instruction mix of $15 \%$ conditional branches, $1 \%$ unconditional branches, $84 \%$ all others, and $60 \%$ of the conditional branches are taken. We have a 4-stage pipeline where branch target locations are computed in the 3rd stage and branch conditions in the 4th stage. Assume no other sources of pipeline stalls.

We want to decide whether to implement "predict taken" or "predict not taken" for branch prediction for this machine. For "predict not taken", even unconditional branches are assumed not taken.
Which of the following is correct?

  1. "predict not taken" is better for this machine.
  2. "predict taken" is better for this machine.
  3. For both "predict taken", "predict not taken" branch predictions, CPI is the $1.38$
  4. For both "predict taken", "predict not taken" branch predictions, CPI is the $1.30$
in CO and Architecture edited by
752 views

1 comment

One of the best and conceptual questions of the AIMT 5. @Deepak Poonia Sir

4
4

1 Answer

6 votes
6 votes

In the context of pipeline, ‘Predict-not-taken’ is a method of branch prediction in which the hardware assumes that the next instruction to be executed will be the instruction following the branch instruction in memory. This (possible) next instruction is placed in the pipe and execution begins. If after the branch is finished executing, it is found that we really wanted to take the branch, then the (possible) next instruction that we had been executing is thrown out by the hardware, and we begin executing the correct instruction, the branch target.

Predict taken: branch penalty $=.15 * .60 * 2+.15 * .40 * 3+.01 * 2=$ .38 That is, of the $15 \%$ conditional branches, if they are taken, we accrue a 2 cycle penalty because we know the branch location in the 3rd stage, and if we find that the branch is not taken (4th stage), we wind up with a 3 cycle penalty. For unconditional branches, we always have a 2 cycle penalty. 

Predict not taken: branch penalty $=.15 * .60 * 3+.15 * .40 * 0+.01 * 3=.30$ Here, if we assume not taken, then conditional branches that are not taken have no penalty but conditional branches taken and unconditional branches always have a 3 cycle penalty. So assume not taken is better for this machine.

edited by

4 Comments

@vijay raj

You are right, but the question asked for making a wrong assumption in predict not taken. But we will only know about it at 4th stage .

Read this line from question:
"branch target locations are computed in the 3rd stage and branch conditions in the 4th stage."

(It is talking about all branches conditions)

2
2


For predict not taken, in case of uncond branch why do we need 3 stalls, it is uncondn branch,so at 3rd stage once the target address is computed the compiler will take the branch right(so 2 stalls)
cpi=1+(0.15*0.6*3)+(0.01*2)=1.29

 

0
0

@DEBANJAN DAS2k

read last line from question:

"For "predict not taken", even unconditional branches are assumed not taken."

0
0
Answer:

Related questions