



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
Material Type: Quiz; Class: Computer System Organization; Subject: Computer Science; University: University of Illinois - Urbana-Champaign; Term: Fall 2005;
Typology: Quizzes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Name: _________________ NetId: _________________
Show all of your work.
We will not answer any questions during the Quiz. If you believe a problem is incorrectly or incompletely specified, make a reasonable assumption and solve the problem. The assumption should not result in a trivial solution. In all cases, clearly state any assumptions that you make in your answers.
1 [10 pts] ARM/THUMB Consider the following C code: if (c >= 0) c = a + b; if (c < 0) d = c + a; if (d >= 0) e = d + 8;
Assume R1 current stores a, R2 stores b, R3 stores c, and R4 stores d. Use R5 to store e. You can use any other registers, but don’t make assumptions about their initial values or about code after the code above.
Use the ARM instruction set, write assembly code for the above code fragment using as few instructions as possible. You can omit the (cond) portion of unpredicated instructions.
Solution: 5 instructions total
MOV{S} R3, R3 //c=c to update condition flags ADD{PL}{S} R3, R1, R2 //c=a+b and update condition flags ADD{MI} R4, R3, R1 //d=c+a MOV{S} R4, R4 //d=d to update condition flags to ensure correctness //in case that the instruction above is not executed ADD{PL} R5, R4, #8 //e=d+
Grading : +1 number of instructions = 5 or fewer +3 correct use of predication +6 consistent code sequence
2 [15 pts] Pipelining Consider the following code: Loop: LD R1, 0(R2) //load R1 from address 0+R DADDI R2, R1, #8 //R2=R1+ DSUB R4, R3, R2 //R4=R3-R BNEZ R4, Loop //branch to Loop if R4!=
Assume the initial value of R3 is R2+80.
If structural hazards are due to write-back contention, assume the earliest instruction gets priority and other instructions are stalled.
a) [10 pts] Show the timing of this instruction sequence for the classic five-stage RISC pipeline with forwarding and bypassing hardware. Use a pipeline timing chart like you did in the homework. Assume that the branch is handled by predicting it as not taken.
Solution:
Instructions 1 2 3 4 5 6 7 8 9 10 11 12 13 LD R1, 0(R2) F D X M W DADDI R2, R1, #8 F s D X M W DSUB R4, R3, R2 F D X M W BNEZ R4, LOOP F s D X M W
LD R1, 0(R2) F D X M W
Clock Cycles
b) [5 pts] If all memory references hit in the cache, how many cycles does this loop take to execute, with forwarding and bypassing? You do not need to compute the answer, but you do need to show the equation that leads to the correct answer.
Solution:
Full credit solution: Look at the code above. Starting from the LD instruction, R1 depends on R2, then R2 depends on R4, and the branch instruction depends on R4. We cannot predict the number of iterations this loop will take. However, from the timing diagram, we know that the last iteration takes 10 cycles, and that the number of cycles between loop instances is 7. Hence, the total number of cycles = (# of iterations - 1) * 7 + 10.
Grading : +2 recognize the number of iterations not predicable +2 recognize the difference between the last iteration and the previous +1 correct equation
Solution: 0100 -> 0. 1100 -> -0.
b) [4 pts] Multiply them as signed fractions (1.3 format) and the result is in 2.6 format.
Solution: 1.100 x 0.100 = 11.11 0000
Grading: +1 result in 2.6 format +3 correct answer
c) [4 pts] Multiply them as unsigned fractions (0.4 format) and the result is in 0.8 format.
Solution: .1100 x .0100 = .0011 0000
Grading: +1 result in 0.8 format +3 correct answer
d) [6 pts] Suppose you add 1.100 and 0.111. Interpret them as signed fractions and that the result is a signed fraction of the same size (1.3 format). What is the sum if the addition is saturating? What if the addition is truncating? What if the addition is rounding?
Solution: Full credit solution: 1.100 + 0.111 = 10.011 = 0.011 (actual correct result stored in computer) There is no overflow, since the sum is 0.375 in 1.3 format. Furthermore, the addition of a positive number and a negative number will never cause overflow. Æ no need for saturation, truncation, or rounding.
Grading: +3 recognize no overflow +3 recognize no need for saturation, truncation, or rounding
If the signed fractions are in 0.4 format and the result is in 0.4 format, then there is an overflow. In that case, 1.0011 -> 0.1111 (saturation) 1.0011 -> 1.001 (truncation) 1.0011 -> 1.010 or 1.001 (rounding) However, the question here states that the format should be 1.3. Partial credit will be given if students approached the problem as a 0.4 format.
Grading: +1 correct saturation +1 correct truncation +1 correct rounding