

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concept of branching in computer architecture and compilers, focusing on the calculation of target addresses, comparison of registers, pipeline penalties, and the use of branch-history tables. It also covers the prediction of branch outcomes in compilers and the impact on pipeline penalties.
Typology: Exercises
1 / 2
This page cannot be seen from the preview
Don't miss anything!


a) During which stage is the target address (address of the instruction to branch to) likely to be calculated?
b) During which stage is the comparison between registers (R3 and R8) likely to be performed?
c) If the branch is taken, then how many instructions will be in the pipeline that need to be thrown away?
d) If the branch is not taken and we continue to fetch instructions sequentially, then there is a branch penalty of ______ cycles.
a) if (x > 0) then b) if (x = 0) then c) for i := 1 to 500 do d) if (ch >= ‘a’ and ch <= ‘z’) then
end if end if end for end if
b) What if the instruction is a branch instruction and it is not in the Branch-History Table?
c) Should the Branch-History Table contain entries for unconditional as well as conditional branch instructions?
Name:______________________
Lecture 5 Page 1
BubbleSort (int n, int numbers[]) Part (a) answer Part (b) answer int bottom, test, temp; boolean exchanged = true; bottom = n - 2; while (exchanged) do exchanged = false; for test = 0 to bottom do if number[test] > number[test + 1] then temp = number[test]; number[test] = number[test + 1]; number[test + 1] = temp; exchanged = true; end if end for bottom = bottom - 1; end while end BubbleSort
a) Where in the code would unconditional branches be used and where would conditional branches be used?
b) If the compiler could predict by opcode for the conditional branches (i.e., select whether to use machine language statements like: “BRANCH_LE_PREDICT_NOT_TAKEN” or “BRANCH_LE_PREDICT_TAKEN"), then which conditional branches would be "PREDICT_NOT_TAKEN" and which would be "PREDICT_TAKEN"?
c) Assumptions: n = 100 and the numbers are initially in descending order before the bubble sort algorithm is called the six-stage pipeline of the text the outcome of conditional branches is known at the end of the EI stage target addresses of all branches is known at the end of the CO stage ignore any data hazards Under the above assumptions, answer the following questions: i) If fixed predict-never-taken is used by the hardware, then what will be the total branch penalty (# cycles wasted) for the algorithm? (Here assume NO branch-history table)
ii) If a branch-history table with one history bit per entry is used, then what will be the total branch penalty (# cycles wasted) for the algorithm? (Assume predict-not taken is used if there is no match in the branch-history table) Explain your answer.
Name:______________________
Lecture 5 Page 2