Presentation is loading. Please wait.

Presentation is loading. Please wait.

Digital DesignFloating-Point Number-0 CS3104: 數位系統導論 Principles of Digital Design [project2] floating-point number addition 吳中浩 教授 助教 高鵬程 國立清華大學資訊工程學系.

Similar presentations


Presentation on theme: "Digital DesignFloating-Point Number-0 CS3104: 數位系統導論 Principles of Digital Design [project2] floating-point number addition 吳中浩 教授 助教 高鵬程 國立清華大學資訊工程學系."— Presentation transcript:

1 Digital DesignFloating-Point Number-0 CS3104: 數位系統導論 Principles of Digital Design [project2] floating-point number addition 吳中浩 教授 助教 高鵬程 國立清華大學資訊工程學系 八十七學年度第一學期

2 Digital DesignFloating-Point Number-1 Scientific Notation 6.02 x 10 1.673 x 10 23 -24 exponent radix (base) Mantissa decimal point Sign, magnitude IEEE F.P. (SP):  1.M x 2 e - 127 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 )

3 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 - 127 SE M N = (-1) 2 (1.M) S E-127 0 < E < 255 Magnitude of numbers that can be represented is in the range: 2 -126 (1.0) to2 127 (2 - 2 23 ) which is approximately: 1.8 x 10 -38 to3.40 x 10 38 (integer comparison valid on IEEE Fl.Pt. numbers of same sign!)

4 Digital DesignFloating-Point Number-3 oExamples: Floating-Point Representation -0.75 = -0.11x2**0 = -1.1x2**(-1) = 1 01111110 10000… i.e. (-1) x (1+.1000 0000 0000 0000 0000 000) x (2 ) 0 = 0 00000000 0... 0 -1.5 = 1 01111111 10... 0 1126

5 Digital DesignFloating-Point Number-4 Floating-Point Addition oBasic addition algorithm: Illustrate: 9.999 ten x 10 + 1.610 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: 1.610 ten x 10 =0.1610 ten x 10 = 0.01610 ten x 10 If we can represent only four decimal digits, so the number is really: 0.016 ten x 10 SETP 3: compute Xm 2 + Ym EX: 9.999 ten + 0.016 ten 10.015 ten The sum is 10.015ten x 10 Xe-Ye 01 1 1 1

6 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: 10.015 ten x 10 = 1.0015 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 : 1.0015 ten x10 = 1.002 x 10 12 22

7 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 0 2 1.69 0 0 7.85 0 2 1.61 = 1.6900 * 10 = -.0785 * 10 = 1.6115 * 10 2-bias - d0. d1 d2 d3... dp-1 0 0 0 0. 0 0 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

8 Digital DesignFloating-Point Number-7 oAlways round up (toward +  ) oAlways round down (toward -  ) oTruncate oRound-to-nearest-even Four Rounding Modes 100. 011. 010. 001. 000. 00.0 00.1 01.0 01.1 10.0 10.1 11.0 11.1 x Round-to- nearest-even(x)

9 Digital DesignFloating-Point Number-8 Example with G, R, and S bits sign exponent mantissa GRS A 0 1000 0011(131) 1.1000 0010 1100 0000 0000 000 000 B 0 0111 1111(127) 1.0000 0011 0000 0101 1001 010 000 B aligned 0 1000 0010(131) 0.0001 0000 0011 0000 0101 100 101 A-B 0 1000 0010(131) 1.0111 0010 1000 1111 1010 011 011 Postnormalization 0 1000 0001(131) 1.0111 0010 1000 1111 1010 011 011 RS Rounding 0 1000 0001(131) 1.0111 0010 1000 1111 1010 011 01 Result 0 1000 0001(131) 1.0111 0010 1000 1111 1010 011 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.

10 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

11 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

12 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.


Download ppt "Digital DesignFloating-Point Number-0 CS3104: 數位系統導論 Principles of Digital Design [project2] floating-point number addition 吳中浩 教授 助教 高鵬程 國立清華大學資訊工程學系."

Similar presentations


Ads by Google