Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Answers to Test 1, Question 1 The function determines if the number is divisible by 6. It performs this by dividing the number first by 3 and then by.

Similar presentations


Presentation on theme: "1 Answers to Test 1, Question 1 The function determines if the number is divisible by 6. It performs this by dividing the number first by 3 and then by."— Presentation transcript:

1 1 Answers to Test 1, Question 1 The function determines if the number is divisible by 6. It performs this by dividing the number first by 3 and then by 2. If they divide without remainder the number is divisible by 6. int div6(int n){ if(n%3 != 0) return 0; if(n%2 != 0) return 0; return 1; }

2 2 Question 2 A single precision floating point number is composed of: –1 bit sign (bit 31) –8 bit exponent (bits 23-30) –23 bit mantissa (bits 0-22) A double precision floating point number is composed of: –1 bit sign (bit 63) –11 bit exponent (bits 52-62) –52 bit mantissa (bits 0-51)

3 3 Question 3 ET A = 135M * 2.9 * 1.5ns = 587M ns = 0.587 sec ET B = 125M *2.2 *(1/450M)ns = 611M ns = 0.611 s A is faster than B by 4% (611/587) Computer A: FE=1.00 (all the instructions are effected), SE = 135/125 = 1.08. (1.00/1.08 + 1 -1)*0.587 = 0.543 sec Computer B: FE=0.40, SE=2.2/1.7 = 1.29 (0.40/1.29 + 0.60)*0.611 = 0.556 sec A is still faster this time by 556/543 = 1.024

4 4 Question 4 Mapping an address into a cache is done by: 1. Computing the block address of the address. Dividing the address into the number of words in each block. 2. Finding the cache location by computing the block address modulo (%) the number of blocks in the cache. 3. The offset of the word in the block, is the remainder of step 1. To get the block address of each address we have to divide by the number of words in the block, which is 1. This number modulo 16 is the cache block the address is mapped to. The only hits are the last accesses to 5, 9, and 17. All the other accesses are misses, so the hit rate is 19%.

5 5 Question 4 (cont) If the block size is 4 we must divide each address by 4 to get the block address and then compute modulo 4. Now we have 1(m), 4(m), 8(m), 5(h), 20(m), 17(m), 19(h), 56(m), 9(m), 11(h), 4(m), 43(m), 5(h), 6(h), 9(m), 17(h). The hit rate is now 37%. For the 3 rd case the mapping is set address modulo number of sets. So each address has to be divided by 8 and then modulo 2 taken: 1(m), 4(m), 8(m), 5(h), 20(m), 17(m), 19(h), 56(m), 9(h), 11(h), 4(m), 43(m), 5(h), 6(h), 9(h), 17(h). The hit ratio is now 50%.

6 6 Question 5 If the block is less than 131064 bytes a bne can be used: bne $a0,$a1,End … End: If the block is larger than 131064 bytes a j must be used: beq $a0,$a1,L1 j End L1: … End:

7 7 Question 5 (cont) If the block spans a 256MB boundary j can't be used. Only jr can be used. The problem is getting the address in a register. Using lui or a shift operation can solve the problem: lui $t0,0xFFDD # li $t0,0xFFDD # sll $t0,$t0,16 addi $t0,$t0,0xCCAA beq $a0,$a1,L1 jr $t0 L1: … End:

8 8 Question 6 AMAT = 0.92*2 + 0.08(0.88*7 + 0.12*12) =2.448 Changing the hit-time of L1 to 1 leads to an AMAT of: 0.92*1 + 0.08(0.88*7 + 0.12*12) = 1.528 Changing the hit-ratio of L2 to 99% leads to an AMAT of: 0.92*2 + 0.08(0.97*7 + 0.03*12) = 2.412 Thus changing the hit-time of L1 is a better choice.

9 9 Question 7 swap: lw $t0,0($a0)# $t0 = *a lw $t1,0($a1)# $t1 = *b ble $t0,$t1,L1 # if $t0 <= $t1 branch sw $t1,0($a0) # *a = *b sw $t0,0($a1) # *b = *a L1: jr $ra # return

10 10 Question 8 mov $t0,$t1 -> add $t0,$t1,$zero li $t0,17 -> addi $t0,$zero,17 bne $t2,$zero,L1 mul $t0,$t1,$t2 -> mult $t1,$t2 mflo $t0 blt $t0,$t1,L1 -> slt $t2,$t0,$t1 bne $t2,$zero,L1


Download ppt "1 Answers to Test 1, Question 1 The function determines if the number is divisible by 6. It performs this by dividing the number first by 3 and then by."

Similar presentations


Ads by Google