






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







The exam is open book, and open notes. There are 3 questions, and each question is worth 35 points; 100 total points is full credit. You will have 75 minutes (from 1:15 to 2:30) to take the exam. Pace yourself; if you find you are spending more than 25 minutes on a problem, come back and finish it later. If a question is ambiguously worded, raise your hand and I will come give you a clarification if appropriate. Important clarifications will be written on the board. Time remaining will be announced periodically. Answers are in red, extra explanation is in blue.
Suppose you are designing an ASIC (Application-Specific Integrated Circuit) and you are trying to decide whether to select a single-precision or double-precision standard FPU cell from your cell library IP vendor. The System Requirements Specification document for your particular application decrees that for sufficient accuracy of calculated results, the hardware must represent all floating-point data values with at least 9 decimal places worth of precision in the significand. a) How many possible sequences of 9 decimal (base-10) digits are there? (Note this is also the number of possible significand values, if 0 is a valid initial digit.) Sequences of 9 digits, like 000,000,000 through 999,999,999, correspond to numbers from 0 through 10^9 −1. There are 10^9 = 1 billion of these. These sequences would also correspond to significand values ranging from 0.00000000 through 9.99999999 (9 digits including one before radix point), or 0.000000000 through 0.999999999 (9 digits after decimal point), depending on the particular normalization convention that is being used. Either of these ranges would represent 9 decimal places worth of precision. b) How many bits, at minimum, would therefore be required to encode an arbitrary significand value, given that the number of possible significand values has to be at least as large as your answer to (a) in order for the binary encoding to obtain the required precision? Show your calculation. (Hint: Remember the logarithm!) Part (a) showed there are at least 10^9 possible significand values if there are at least 9 decimal places of precision. To represent any of r values takes b =log 2 r bits (see eq. on p. 162). For r = 10^9 , b = log 2 109 = ln 10^9 /ln 2 = 29.8973… (used calculator). So, at least 30 bits in the significand are required to represent any of at least 10^9 different significand values, and therefore at least 30 significand bits are needed to achieve 9 decimal places of precision.
c) Therefore, can an IEEE single-precision FPU be used in your ASIC? Why or why not? Explain. No, because single precision format only provides 23 bits in the significand, and we need at least 30. Note that it does not matter that the entire single-precision word is 32 bits (which is greater than 30), because 9 of those bits are in the sign and exponent fields, which do not contribute to the precision of the set of numbers represented – only to its range. d) Could an IEEE double-precision FPU be used in your ASIC? Why or why not? Explain. Yes, because double precision has 52 bits in the significand, which is more than 30, so we have at least 9 decimal places of precision (actually we have 52/log 2 10 ≈ 15.6 decimal digits’ worth).
f) Is the single-precision representation of 10^9 an exact representation of that number? What if we had wanted to represent (say) the number 10^9 − 1 = 999,999,999 10 instead? Does that number have an exact representation in single precision? Explain how you figured out the answer. Yes, because when we rounded off 7,236,391.99999 to 7,236,392 in part (e) we were only correcting a small imprecision in our hand- calculator, not introducing any error into the representation. In this case, we were lucky that even though single-precision doesn’t have enough significand bits to exactly represent all 10^9 numbers in (say) the range 1-to-a-billion precisely, its representation of the specific number 10^9 happens to be an exact one. This is because 10^9 is divisible by 2^9 , and so there are enough trailing 0’s so that when we round off the significand to 23 bits we don’t actually lose any 1’s. To see this, convert 1,000,000,000 10 to binary on your calculator; you will get: 11,1011,1001,1010,1100,1010,0000,0000 (exact, 30-bit binary integer) and shifting the decimal point 29 places to the left gives us 1.1101,1100,1101,0110,0101,0000,0000,0 (exactly) × 2^29 where we have underlined the 23 bits that will be explicitly coded in the signifcand field. Notice that all 29-23 = 6 of the bits that get truncated away from the right end of the significand when we round it to 23 bits are all zeroes! This is because 10^9 is divisible by 2^9 , so there are 9 trailing 0’s, which is more than the number of bits getting truncated away. The next part of the question asks if we can exactly represent 999,999,999. Well no, because in part (a) we already identified that there isn’t enough precision for a 1-in-a-billion (or 9 significant decimal digits) level of precision; thus if the representation for 10^9 is exact, then the representation of a neighboring integer such as 10^9 −1 cannot be. In more detail, because the exponent is 29, and 2^29 /2^23 = 2^6 = 64, we know that the adjacent exactly-representable numbers (of magnitude around 10^9 ) are 64 apart from each other. So, the next-smaller exactly
representable number before 10^9 is 10^9 −64 = 999,999,936; while the next-larger one is 10^9 +64 = 1,000,000,064. In other words, the gap size is 64 because we’re rounding off the low 6 bits of the significand from the integers in this range, because their significands are 29 bits long (after the radix point) and we’re only keeping the first 23 bits after the radix point.
Label of An instruction that could Wire or bus be used to test it rs add RegDst andi Mistake in exam - this can’t be the culprit anyway Next PC any instruction inst any inst. op any inst. except R-type instructions (for which it’s 0 anyway) imm any immediate instruction rs any instruction that has an rs operand (rs) any instruction that has an rs operand rt -> mux any instruction that uses rt as a destination operand RegWrite any instruction that writes a register ALUSrc any immediate instruction ALUFunc any instruction but LUI (it has ALUFunc=0 anyway) ALUOut any instruction that uses the ALU Data addr SW is the only other instruction that uses this line Data out No other instructions besides LW use this line DataRead No other instructions besides LW use this line Register input Any instruction that writes to the register file RegWrite Any instruction that writes to the register file c) Solve the diagnostic problem. Suppose that after some experimenting, you discover that SW is also malfunctioning, but that all other instructions are working correctly. Assuming that only a single segment of a given wire or bus in the top-level schematic is broken, which one must it be? How do you know? It must be “Data addr” because this is the only line that is used only by LW and SW. d) Assuming your answer to part (c) is correct, if any broken wires (including data wires) manifest themselves as “stuck-at-0” signals, then what are the LW and SW instructions actually doing in the malfunctioning chip (instead of the thing that they are supposed to be doing)? If the entire “Data addr” bus is in a stuck-at-0 state, then all loads and stores will access memory at address 0. So, all LWs will return the last value that was SW’ed, regardless of what addresses were specified.
The following MIPS subrotuine takes a 32-bit unsigned dividend and a 32-bit unsigned divisor in registers $a0 and $a1, respectively, and returns their 32-bit unsigned quotient and remainder in registers $v0 and $v1, respectively.
line # Pseudocode comments (using C/C++ syntax)... 01 myDivide: move $v0, $zero # quotient = 0; 02 move $t0, $zero # position = 0; 03 leftShift: andi $t1, $a1, 0x80000000 # while (divisor & (1<<31) 04 bne $t1, $zero, doTop # != 0) { 05 addi $t0, $t0, 1 # position++; 06 sll $a1, $a1, 1 # divisor <<= 1; 07 b leftShift # } 08 doTop: sll $v0, $v0, 1 # do { quotient <<= 1; 09 sltu $t1, $a0, $a1 # temp = (dividend < divisor); 10 bne $t1, $zero, endIf # if (temp == 0) { // If d’dend >= d’sor 11 subu $a0, $a0, $a1 # dividend -= divisor; 12 or $v0, $v0, 1 # quotient |= 1; } 13 endIf: srl $a1, $a1, 1 # divisor >>= 1; 14 addi $t0, $t0, -1 # position--; 15 bgez $t0, doTop # } while (position >= 0); 16 endFor: move $v1, $a0 # remainder = dividend; 17 jr $ra # return quotient($v0) & remainder($v1). Consider calling this subroutine with input values $a0=99, $a1=9. a) First, write out the given input values as full 32-bit binary numbers. bit #: 31 MSB 24 23 16 15 8 7 LSB 0 $a0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 $a1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 b) After all iterations of the leftShift while loop (lines 03-07) have been completed, and the PC arrives at line 08 for the first time, what will the new contents of $a1 be at that point? bit #: 31 MSB 24 23 16 15 8 7 LSB 0 $a1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 c) When line 08 is first reached, (i) what will be the value of register $t0? So, (ii) how many iterations of the do loop (lines 08-15) will occur? Also, (iii) Throughout how many of these iterations will the quotient register ($v0) continue to just contain 0? (i) It will be 28, the number of positions that the divisor was shifted left. (ii) Thus the DO loop will iterate 29 times (from position=28 all the way down to position=0; we do a comparison at each of these 29 positions)
d) Hand-simulate the execution of lines 08 through 15 for three of the loop iterations, starting from the iteration in which $a1 starts with the value 144 (which is 9<<4 = 9 ×16). Indicate each line of code executed and each value written back to a register. We have already indicated the values of the registers (at this particular time point) at the top of the table, and filled in the first six lines of the table for you. Also record the branch behavior, as shown. Note: the initial iteration number was miswritten as 28 on the actual exam, and was misreported to be 24 in an in-class announcement! Iter. No. Line No. $v0^ $t0^ $t1^ $a0^ $a^ Branch behavior, taken v. not Branch dest (if taken) Initially: 0 4 don’t care 99 144 25 08 0 25 09 1 25 10 taken endIf (13) 25 13 72 25 14 3 25 15 taken doTop (08) 26 08 0 26 09 0 26 10 not taken 26 11 27 26 12 1 26 13 36 26 14 2 26 15 taken doTop (08) 27 08 2 27 09 1 27 10 taken endIf (13) 27 13 18 27 14 1 27 15 taken doTop (08) 28 08 4 28 09 0 28 10 not taken 28 11 9 28 12 5 28 13 9 28 14 0 28 15 taken doTop (08) 29 08 10 29 09 0 29 10 not taken 29 11 0 29 12 11 29 13 4 29 14 − 29 15 not taken The first iteration (which is really the 25th) is already given in black, this, together with the next two, (shown in red) form the required three
iterations. There are two more iterations after this, shown in blue, but you didn’t have to write these. However it would be a good way to check your technique. Note that the final value of $v0 is 11, which is the correct quotient, and the final value of $a0 (which will be moved to $v1 on line 16) is 0, which is the correct remainder. Since by the end of iteration 29, $t0 is not greater than or equal to 0 any more, the bgez isn’t taken, and we exit the loop at this point, so there are no more iterations after this.