Computer Architecture Homework #2 Due: 9/26/03 (F)

You are to assume the same 6-stage pipeline as discussed in class (see http://www.cs.uni.edu/~fienup/cs142f03/lectures/lec6.htm) when answering these questions.

Assume that the first register in an arithmetic operation is the destination register, e.g., in "ADD R3, R2, R1" register R3 receives the result of adding registers R2 and R1.

1. What would the timing be without bypass-signal paths/forwarding (use "stalls" to solve the data hazard)?

(This code might require more that 15 cycles)

  Time
Instructions 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
ADD R3, R2, R1 FI DI CO FO EI WO                  
SUB R4, R5, R6   FI                          
LOAD R8, 4(R3)                              
SUB R6, R4, R8                              
STORE R4, 16(R6)                              
ADD R5, R3, R4                              

2. What would the timing be with bypass-signal paths? (This code might require more that 15 cycles)

  Time
Instructions 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
ADD R3, R2, R1 FI DI CO FO EI WO                  
SUB R4, R5, R6   FI                          
LOAD R8, 4(R3)                              
SUB R6, R4, R8                              
STORE R4, 16(R6)                              
ADD R5, R3, R4                              

3. Draw ALL the bypass-signal paths needed for the above example.

4. Consider the following bubble sort algorithm that sorts an array numbers[1..n]:

BubbleSort (int n, int numbers[])

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:

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) For partial credit, explain your answer.

ii) If static predict-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.

iii) 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.

iv) If a branch-history table with two history bits per entry is used as in Figure 8.12, 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.