Download Impact of Augmenting Instruction Set Architecture on Instruction Execution and Encoding and more Assignments Chemistry in PDF only on Docsity!
CSE 30321 – Computer Architecture I – Fall 2010
Midterm Exam
October 1 4 , 20 10
Test Guidelines:
- Place your name – or at least your initials! – on *** **EACH***** page of the test in the space provided. Be sure to do this on p. 1 and 2!
- Answer every question in the space provided. If separate sheets are needed, make sure to include your name and clearly identify the problem being solved.
- Read each question carefully. Ask questions if anything needs to be clarified.
- The exam is open book and open notes.
- All other points of the ND Honor Code apply. By writing your name on the exam, you agree to abide by the ND Honor Code.
- Upon completion, please turn in the test and any scratch paper that you used. Suggestion:
- Whenever possible, show your work and your thought process. This will make it easier for us to give you partial credit. Grading will be done on Friday!
Score Sheet
Question Possible Points Your Points 1 15 2 15 3 20 4 10 5 15 6 10 7 15 Total 100
Question B: ( 5 points) Now, assume that the 20 new instructions have all been added. Their addition has resulted in changes to the state diagram discussed in lecture. A portion of the new finite state diagram is shown below. Given this new state diagram , how many clock cycles will the code (that is also shown below) take to run? Code: Mov R1, # Mov R2, # Mov R4, # Sub R5, R4, R Sub R5, R5, R Jumpz R5, X Add R1, R1, R X: Add R1, R2, R Mov 10, R Answer: Mov R1, #1 # R1 1; 4 CCs Mov R2, #2 # R2 2; 4 CCs Mov R4, #4 # R4 4; 4 CCs Sub R5, R4, R2 # R5 R4 – R2 = 2 3 CCs Sub R5, R5, R2 # R5 R5 – R2 = 0 3 CCs Jumpz R5, X # Jump to X 3 CCs Add R1, R1, R1 # SKIP X: Add R1, R2, R4 # R1 R2 + R4 = 6 3 CCs Mov 10, R1 # M(10) R1 4 CCs
Total: 28 CCs Question C: ( 5 points) In what clock cycles does R1 change state? (i.e. when is new data put into R1 available?) Answer: R1 changes state after the instruction “Add R1, R2, R4” is executed. This is in cycle 24 – which means that R1 data is available at the beginning of clock cycle 25. It also changes state in CC #5. Comments: The most common mistakes I observed had to do with Parts B and C. If a mistake was made on Part B, it generally had to do with the fact that you either assumed that both Add instructions were executed, or miscounted the cycles from the state diagram. If a mistake was made on Part C, you generally assumed that data was available in the last cycle of execution – not the next cycle. (This is why the comment “when is data put into R1 available?” was included.)
Problem 2 : ( 15 points, Course Goal #4)
Question A: ( 4 points) Consider a hypothetical branch-if-equal instruction that is 32 bits long:
- 6 bits are used to encode the opcode
- 6 bits are used to encode one register number
- 6 bits are used to encode another register number
- 14 bits are used to encode an offset that will be added to the program counter (PC) if the branch ends up being taken, and a new instruction address is required. o (The number is not in 2s complement form, and all 14 bits can encode a constant.) Thus, the instruction syntax might be: BEQ R12, R11, X
- If R12 == R11, the PC will be set to PC + X instead of PC + 4. Given this instruction, is the code shown in the table below valid? Why or why not? Address Instruction 5000 … 5004 BEQ R12, R11, X 5008 Add R1, R2, R … … X: 21256 Sub R1, R2, R Answer: Yes, this code is valid. The 14 bit offset allows you to encode a number that is as large as 2^14 – 1 (=16383). Thus, even if the PC has not yet been incremented, you can reach address 2138 4 (5004 + 16383), which is beyond address 21256. Comments: Most students got this question right. Question B: ( 4 points) Assuming that the PC has already been incremented by 4 when the comparison for the BEQ instruction at address 5004 is made, how many instructions away from the BEQ instruction could we reach? Answer: Floor((2^14 - 1) / (2^2 )) = 4095 + 1 = 4096.
- The floor function is needed because the address must be a multiple of 4. Comments: Some assumed that the PC was not incremented and based their answer accordingly. This received full credit as long as your answer was explained correctly.
Problem 3 : ( 20 points, Course Goal #2)
Assume that to spell check a large file, 820,000,000 instructions are needed. The instructions in the program are broken down into 4 different classes, and each class requires N clock cycles to execute. Specific information is given in the table below. (Here, N is the same as in the MIPS multi-cycle datapath discussed in class.) Instruction Class Clock Cycles per Instruction Number of Instructions Branch 3 150,000, Store 4 185,000, Load 5 260,000, ALU / R-type 4 225,000, Question A: ( 5 points) If the total execution time for this program is found to be 1.57 seconds, what is the clock cycle time of the computer on which it was run? Answer: We can apply the CPU time formula: CPU time = IC x CPIavg x CC Time, and solve for CC Time.
820 , 000 , 000 × 3
( +^4
( +^5
( +^4
. ×^ N^ =^ 1.57 s
Thus, the clock cycle time is 4.63 x 10-^10 s. This is a 2.16 GHz machine. Comments: Many of you lost a point on this question because you provided a clock rate (i.e. Hz, GHz, etc.) instead of a clock cycle time. The units should be in seconds. Expect this topic to come up again on the final exam!
Question B: (10 points) Assume that as part of the 820,000,000 instruction spell check, 25% of all load instructions are immediately followed by an ALU / R-type instruction that uses the data that was just loaded. To speed up this program, we are contemplating adding a new type of instruction – an ALU instruction where one of the source operands is a value from memory.
- This new instruction will replace the previous, 2 instruction sequence.
- It will take 7 clock cycles. Will this change offer any speedup over the original design? If so, how much? You may assume that the clock rate does not change and your answer to this question does not depend on your answer to Question A. Answer: We will need to apply the CPU time formula again, but first need to calculate the new number of load, ALU / R-type, and “new type” instructions:
- The # of branches remains constant: 150,000,
- The # of stores remains constant: 185,000,
- The new # of loads is: (260,000,000 x 0.75) = 195,000,
- The new # of ALUs is: (225,000,000 – 65,000,000) = 160,000,
- The number of new instructions is: (260,000,000 x 0.25) = 65,000, Total: 755,000, Thus, the new CPU time is: 755 , 000 , 000 × 3 150 , 000 , 000 755 , 000 , 000 "
$ % & ' +^4 185 , 000 , 000 755 , 000 , 000 "
$ % & ' +^5 195 , 000 , 000 755 , 000 , 000 "
$ % & ' +^4 160 , 000 , 000 755 , 000 , 000 "
$ % & ' +^7 65 , 000 , 000 755 , 000 , 000 "
$ % & ' ( )
,
- ×^ N …which can be expressed as: 3,260,000,000 N This can be compared to a similar expression from Part A: 3,390,000,000 N. Thus, the speedup with the new design is ~4%. Comments: A few tried to apply Amdhal’s Law (which did not work). Most realized that you needed to determine a new number of ALU, load, and new instructions and re-calculate CPU time. Even if other mistakes were made, I was really looking for you to show this thought process. If you did, you received a majority of points for this problem.
Problem 4 : ( 10 points, Course Goal #3)
The number of instructions (of a given type) needed to encrypt and decrypt a message are as shown in the table below: Instruction Class Cycles Per Instruction Encrypt Decrypt Branch 3 4,000,000 4,000, Store 4 10,000,000 9,000, Load 5 28,000,000 25,000, ALU / R-type 4 23,000,000 22,000, Totals: 65,000,000 60,000, You are considering changing the datapath that these benchmarks are run on so that a load instruction completes in 4 CCs instead of 5. Because the load instruction has to now do more work in a given clock cycle, that clock cycle will need to get longer. What clock cycle slow down is tolerable such that the performance of the encrypt and decrypt benchmarks is not degraded? You may assume that for every message decrypted, a message is also encrypted (and thus, there is equal use). Answer: We need to set the execution time for the base case equal to the execution time for the new case (with the slower clock rate) and find out what degradation is tolerable.
- We can simply add the number of instructions for encryption to the number of instructions for decryption.
- Instruction counts will cancel (as seen in the previous problems) and are thus not shown / used. (3)(8,000,000) + (4)(19,000,000) + (5)(53,000,000) + (4)(45,000,000) = [(3)(8,000,000) + (4)(19,000,000) + (4)(53,000,000) + (4)(45,000,000)](X * N) (545,000,000 * X) = (473,000,000 * X * N) N = (545,000,000 * X) / (473,000,000 * X) N = 1. Therefore, a slowdown of ~15% is tolerable. Comments: As seen from the stats, most got this question right. (In fact, the median was a 10.)
Problem 5 : ( 15 points, Course Goal #5)
Below is a state diagram for a hypothetical processor. Consider the following for loop: for (i=0; i= 5 , Version 2 will always be most efficient. Question B: (5 points) Given your answer, how could you make the above MIPS code even more efficient? Answer: Make the loop iterate in chunks of 4, not 1. Load #1! Load #2! Load #3! Store #1! Store #2! Branch! R-type #1! R-type #2! Mult #1! Fetch! Decode! Mult #2! Mult #3! Mult #4! Mult #5!
Problem 6 : ( 10 points, Course Goal #4)
Assume the following: o Data for 4 arrays – A, B, C, and X – is stored in memory. o You may assume that: o The data elements for array A are stored in sequential memory addresses. o The data elements for array B are stored in sequential memory addresses. o The data elements for array C are stored in sequential memory addresses. o The data elements for array X are stored in sequential memory addresses. o However, arrays A, B, and C are not stored sequentially in memory. o The starting address of array A is contained in $1. o The starting address of array B is contained in $2. o The starting address of array C is contained in $3. o The starting address of array X is contained in $4. Write the MIPS assembly instruction for the following statement: X[i] = A[B[i]] + C[B[i+4]]; To receive full credit, your answer should contain no more than 10 instructions. You may assume i maps to $5. Please comment your code! Answer: 1 st, calculate the address of B[i]
- sll $6, $5, 2 # multiply i*
- add $7, $2, $6 # add i*4 to the base address of B. 2 nd, load B[i]
- lw $8, 0($7) # load B[i] into a register 3 rd, load B[i+4]
- lw $9, 16 ($7) # load B[i+4] into a register; use start of i previously calculated 4 th, load A[B[i]]
- add $8, $8, $
- lw $10, 0($8) # data in B[i] is in $8 and is address needed for A 5 th, load C[B[i+4]]
- add $9, $9, $
- lw $11, 0($9) # data in B[i+4] is in $9 and is address needed for C 6 th, do the add
- add $12, $10, $11 # add A[B[i]] + C[B[i+4]] 7 th, calxulate the address of X[i]
- add $13, $4, $6 # we still have the old value of i*4 in $ 8 th, do the store
- sw $12, 0($13) # write data to memory address that maps to X[i] Comments: My solution here reflects a slightly different solution than that which is hinted at by the problem (i.e. create a 10 instruction solution). (The class last year could make an assumption about ix4.) The most common reasons for lost points usually involved improperly formatted lw and sw instructions. A very common mistake was related to instruction 3 in my solutions – i.e. to get i+4, you needed to use 16($x) rather than 4($x).
Question A: ( 3 points) Write the MIPS assembly for the line “return x+x;” in function_call_3. Answer: add $v0, $a0, $a0; jr $ Question B: ( 3 points) What stack operations – if any – take place inside of function_call_1? You can assume that function_call_1 is not a system call. Answer:
- Save the $ra because of a nested function call.
- Save $s1 because it is used in main. Question C: ( 3 points) What MIPS instruction(s) would you expect to see before function_call_1 in main() – given the MIPS calling convention? Answer:
- We would copy the data in $s6, $s7, and $t1 into argument registers – $a0, $a1, and $a2.
- We would call “jal function_call_1”
- We DO NOT need to save $t1 to the stack because we never use it again Question D: ( 3 points) What register would the variable x map to in the line “x = function_call_1(o,p,q)” in main()? Answer:
- $v Question E: ( 3 points) What stack operations – if any – must main() perform? Answer:
- Data in variables x would have needed to be saved to the stack.
- Therefore, we would need to pop this value off to do “z=x+y”