Download Selection Sort Algorithm - Intro to Computer Architecture - Homework and more Exercises Computer Architecture and Organization in PDF only on Docsity! Computer Architecture HW #3 1. Consider the following selection sort algorithm that sorts an array numbers: SelectionSort(int length; int numbers[ ]) int firstUnsortedIndex, testIndex, smallestIndex, temp for firstUnsortedIndex = 0 to (length-2) do smallestIndex = firstUnsortedIndex for testIndex = firstUnsortedIndex + 1 to length - 1 do if numbers[ testIndex ] < numbers[ smallestIndex ] then smallestIndex = testIndex end if end for temp = numbers[ firstUnsortedIndex ] numbers [ firstUnsortedIndex ] = numbers [ smallestIndex ] numbers [ smallestIndex ] = temp end for end SelectionSort 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: length = 100 and the numbers are initially in ascending order before the selection 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 static 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) For partial credit, explain your answer. 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) For partial credit, explain your answer. iii) If a branch-history table with two history bits per entry is used as in Figure 11.16, 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) For partial credit, explain your answer. Docsity.com