I don't understand this solution at all. Can someone please help me with this? This is the question and Here is the answer
-
1If you literally understand nothing in the question or answer, go see your professor. If you do understand something, you need to explain what you do understand so the answer can be smaller than a textbook. [ask] has some description of writing good questions. – Peter Cordes Apr 18 '18 at 23:17
1 Answers
During the first cycle, your branch predictor is at 00 (a 00 or a 01 assumes branch not take). Hence, when branching, we assume it is not taken and start executing addi. Because d is equal to 0, the assumption of the branch being not taken is correct. We stay with branch predictor 00.
For the next branch that comes up, we still have a 00 predictor and assume not taken. That is correct as d is equal to 1 (only branch if d is not equal to 1).
Next up we are back at the first branch. Remember, d is now 1. According to our 00 predictor, branch should not be taken. However, when the branch is actually calculated we find that 1 is not 0 and thus, the branch is taken (mispredictions++).
Because the branch was taken, d is still 1. Because the last branch was taken our predictor is 01, which still tells us to predict branch not taken. Because d is equal to 1, this prediction was correct.
We are now back at the top with a d value of 2 (it must have been incremented elsewhere in the code). Our branch predictor yet again is 00 and tells up to not take the branch. It is wrong when we take it.
Because we took the branch, we increment the predictor to 01. This still tells us to not take the branch. This is wrong as d is now 2. Hence, the final branch is mispredicted.
Hence, the total of three mispredictions.

- 55
- 1
- 6