Digital DesignFloating-Point Number-0 CS3104: 數位系統導論 Principles of Digital Design [project2] floating-point number addition 吳中浩 教授 助教 高鵬程 國立清華大學資訊工程學系 八十七學年度第一學期
Digital DesignFloating-Point Number-1 Scientific Notation 6.02 x x exponent radix (base) Mantissa decimal point Sign, magnitude IEEE F.P. (SP): 1.M x 2 e oIssues: m Arithmetic (+, -, *, / ) m Representation, Normal form m Range and Precision m Rounding m Exceptions (e.g., divide by zero, overflow, underflow) m Errors m Properties ( negation, inversion, if A = B then A - B = 0 )
Digital DesignFloating-Point Number-2 Floating-Point Representation Representation of floating point numbers in IEEE 754 standard: single precision 1823 sign exponent: excess 127 binary integer mantissa: sign + magnitude, normalized binary significand w/ hidden integer bit: 1.M actual exponent is e = E SE M N = (-1) 2 (1.M) S E < E < 255 Magnitude of numbers that can be represented is in the range: (1.0) to2 127 ( ) which is approximately: 1.8 x to3.40 x (integer comparison valid on IEEE Fl.Pt. numbers of same sign!)
Digital DesignFloating-Point Number-3 oExamples: Floating-Point Representation = -0.11x2**0 = -1.1x2**(-1) = … i.e. (-1) x ( ) x (2 ) 0 = =
Digital DesignFloating-Point Number-4 Floating-Point Addition oBasic addition algorithm: Illustrate: ten x ten x 10 Assume that 4 decimal digits of the significand and two decimal digits of the exponent. STEP 1: compute Ye - Xe (getting ready to align binary point) STEP 2: right shift the smaller number, e.g., Xm, that many positions to form Xm 2 EX: ten x 10 = ten x 10 = ten x 10 If we can represent only four decimal digits, so the number is really: ten x 10 SETP 3: compute Xm 2 + Ym EX: ten ten ten The sum is ten x 10 Xe-Ye
Digital DesignFloating-Point Number-5 Floating-Point Addition oBasic addition algorithm (continue) : if representation demands normalization, then normalize: STEP 4: left shift result, decrement result exponent (e.g.,0.001xx) right shift result, increment result exponent (e.g., 101.1xx) EX: we pick up the normalized form: ten x 10 = ten x 10 NOTE: check overflow or underflow during the shift STEP 5: round the mantissa continue until MSB of data is 1 (NOTE: Hidden bit in IEEE Standard) EX: we must round the number : ten x10 = x
Digital DesignFloating-Point Number-6 Extra Bits for Accuracy oExtra bits during intermediate calculations to help rounding, to get closer to actual number m Two extra bits on the right in IEEE 754: guard and round m E.g., base = 10 precision = 3 bit m Guard bits: digits to the right of mantissa to guard against loss of digits => can later be shifted left into mantissa during normalization (especially when the two numbers are very close, or when multiplication) m Round bits: after the guards being shifted into mantissa, the result can be rounded according to the round bits m Sticky bit: additional bit to the right of the round digit to better fine tune rounding = * 10 = * 10 = * 10 2-bias - d0. d1 d2 d3... dp X... X X X S X X S + Sticky bit: set to 1 if any 1 bits fall off the end of the round digit
Digital DesignFloating-Point Number-7 oAlways round up (toward + ) oAlways round down (toward - ) oTruncate oRound-to-nearest-even Four Rounding Modes x Round-to- nearest-even(x)
Digital DesignFloating-Point Number-8 Example with G, R, and S bits sign exponent mantissa GRS A (131) B (127) B aligned (131) A-B (131) Postnormalization (131) RS Rounding (131) Result (131) Note1: The original G bit can serve an R bit, and the original R and S bits must be ORed in order to generate a new sticky bit. Note2: If the Boolean expression RS + R S’L = R (S + L) where L is LSB of the resultant significand equals 1, we must round up.
Digital DesignFloating-Point Number-9 Flow of Floating-Point Addition Start 1. Compare the exponents of the two numbers. Shift the smaller number to right until its exponent would match the larger exponent. 2. Add the significands 3. Normalize the sum, either shifting right and incrementing the exponent or shifting left and decrementing the exponent. 4. Round the significand to the appropriate number of bits Done Overflow or Underflow? Exception Yes No Still normalized? Yes No
Digital DesignFloating-Point Number-10 Architecture Example Sign Exponent Significand Small ALU Big ALU 0 1 Exponent difference 0 1 Increment or Decrement Shift left or right Sign Exponent Significand Rounding Hardware Control Shift right
Digital DesignFloating-Point Number-11 Schedule and score rules oSchedule: Project 2-1 (deadline on 11/30): Step1 and 2 Project 2-2 (deadline on 12/21): Step3 (Post-normalization) Project 2-3 (deadline on 01/11): Step4 (Rounding) oScore rules: (1). Completeness. (2). Modulize. (3). Architecture.