230 likes | 249 Views
Learn about the IEEE 754 Floating Point format, arithmetic operations, and MIPS Floating Point instructions. Understand the motivation behind floating point representation and its applications.
E N D
Computer Architecture Lecture 9 - Floating Point2011 Reading: 3.6-3.9 Homework: 3.30, 3.35, 3.37, 3.38, 3.40, 3.44 Why did the Ariane 5 Explode?(image source: java.sun.com)
Outline - Floating Point • Motivation and Key Ideas 3 • IEEE 754 Floating Point Format • Floating Point Arithmetic • MIPS Floating Point Instructions • Summary
Floating Point - Motivation • Review: n-bit integer representations • Unsigned: 0 to 2n-1 • Signed Two’s Complement: - 2n-1 to 2n-1-1 • Biased (excess-b): -b to 2n-b • Problem: how do we represent: • Very large numbers 9,345,524,282,135,672, 2354 • Very small numbers 0.00000000000000005216, 2-100 • Rational numbers 2/3 • Irrational numbers sqrt(2) • Transcendental numbers e, π
Fixed Point Representation • Idea: fixed-point numbers with fractions • Decimal point (binary point) marks start of fraction • Decimal: 1.2503 = 1 X 100 + 2 X 10-1 + 5 X 10-2 + 3 X 10-4 • Binary: 1.0100001 = 1 X 20 + 1 X 2-2 + 1 X 2-7 • Problems • Limited locations for “decimal point” (binary point”) • Won’t work for very small or very larger numbers
Exponent Significand (mantissa) Radix (base) Another Approach: Scientific Notation • Represent a number as a combination of • Mantissa (significand): Normalized number AND • Exponent (base 10) • Example: 6.02 X 1023
Exponent Radix (2) Leading ‘1’ (Implicit) Significand (mantissa) Floating Point • Key idea: adapt scientific notation to binary • Fixed-width binary number for significand • Fixed-width binary number for exponent (base 2) • Idea: represent a number as 1.xxxxxxxtwo X 2yyyy • Important Points: • This is atradeoff between precision and range • Arithmetic is approximate - error is inevitable!
Outline - Floating Point • Motivation and Key Ideas • IEEE 754 Floating Point Format 3 • Floating Point Arithmetic • MIPS Floating Point Instructions • Summary
Bias Bias IEEE 754 Floating Point • Single precision (C/C++/Java float type) Value N = (-1)S X 1.F X 2E-127 • Double precision (C/C++/Java double type) Value N = (-1)S X 1.F X 2E-1023 The exponent represents both positive and negative values. To do this, a bias is added to the actual exponent in order to get the stored exponent. For IEEE SP , this value is 127 to represent 0, thus, a stored value of 200 indicated an exponent of (200 – 127) = 73. an exponent of 3 is stored as 130. an exponent of -2 is stored as (-2 +127) = 125. For DP bias = 1024.
Floating Point Examples • 8.75ten = 1 X 23 + 1 X 2-1 + 1 X 2-2 = 1.00011 X 23 • Single Precision: • Significand: 1.00011000…. (note leading 1 is implied) • Exponent: 3 + 127 = 130 = 10000010two • Double Precision: • Significand: 1.00011000… • Exponent: 3 + 1023 = 1026 = 10000000010two
Floating Point Examples • -0.375ten = 1 X 2-2 + 1 X 2-3 = 1. 1 X 2-2 • Single Precision: • Significand: 1.1000…. • Exponent: -2 + 127 = 125 = 01111101two • Double Precision: • Significand: 1.1000… • Exponent: -2 + 1023 = 1021 = 01111111101two
Floating Point Examples • Q: What is the value of the following single-precision word? • Significand = 1 + 2-1 + 2-4 + 2-8 + 2-10 + 2-12 • Exponent = 8 - 127 = -119 • Final Result = (1 + 2-1 + 2-4 + 2-8 + 2-10 + 2-12) X 2-119 = 2.36 X 10-36
Outline - Floating Point • Motivation and Key Ideas • IEEE 754 Floating Point Format • Floating Point Arithmetic 3 • MIPS Floating Point Instructions • Rounding & Errors • Summary
Floating Point Addition Add: 9.999 x 101to 1.610 x 10-1 Step 1: Normalize the smaller number to fit with the larger: 0.0161 x 101 If we can represent only 4 digit number so it becomes: 0.016 x 101 Step 2: 9.999 0.016 10.015 (not in normalized scientific notation Step 3: 10.015 x 101= 1.0015 x 102
Floating Point Addition (Fig. 3.16) 1. Align binary point to number with larger exponent 2. Add significands 3. Normalize result and adjust exponent 4. If overflow/underflow throw exception 5. Round result (go to 3 if normalization needed again) A 1.11 X 20 1.11 X 20 1.75 + B + 1.00 X 2-2 + 0.01 X 200.25 10.00 X 20 (Normalize) 1.00 X 21 2.00
Floating Point Multiplication (Fig. 3.18) 1. Add 2 exponents together to get new exponent (subtract 127 to get proper biased value) 2. Multiply significands 3. Normalize result if necessary (shift right) & adjust exponent 4. If overflow/underflow throw exception 5. Round result (go to 3 if normalization needed again) 6. Set sign of result using sign of X, Y
Outline - Floating Point • Motivation and Key Ideas • IEEE 754 Floating Point Format • Floating Point Arithmetic • MIPS Floating Point Instructions 3 • Summary
MIPS Floating Point Instructions • Organized as a coprocessor • Separate registers $f0-$f31 • Separate operations • Separate data transfer (to same memory) • Basic operations • add.s - single add.d - double • sub.s - single sub.d - double • mul.s - single mul.d - double • div.s - single div.d - double
MIPS Floating Point Instructions (cont’d) • Data transfer • lwc1, swcl (l.s, s.s) - load/store float to fp reg • l.d, s.d - load/store double to fp reg pair • Testing / branching • c.lt.s, c.lt.d, c.eq.s, c.eq.d, … compare and set condition bit if true • bclt - branch if condition true • bclf - branch if condition false
Outline - Floating Point • Motivation and Key Ideas • IEEE 754 Floating Point Format • Floating Point Arithmetic • MIPS Floating Point Instructions • Summary
Addendum - Why Did the Ariane 5 Explode? • In 1996 Ariane 5 Flight 501 exploded after launch. • Estimated cost of accident: $500 million
Addendum - Why Did the Ariane 5 Explode? • The cause was traced to the Inertial reference system (SRI). • Both the main and backup SRI failed. • Both units failed due to an out-of-range conversion • Input: double precision floating point • Output: 16-bit integer for “horizontal bias” (BH) • Careful analysis during software design had indicated that BH would “fit” in 16 bits • So, why didn’t it fit?
Addendum -Why did the Ariane 5 Explode? • Careful analysis during software design had indicated that BH would “fit” in 16 bits • BUT, all analysis had been done for the Ariane 4, the predecessor of Ariane 5 - software was reused • Since Ariane 5 was a larger rocket, the values for BH were higher than anticipated • AND, there was no handler to deal with the exception! • For more information: • http://www.ima.umn.edu/~arnold/disasters/ariane.html • Or, Google “Ariane 5 Flight 501”
Summary - Chapter 3 • Important Topics • Signed & Unsigned Numbers (3.2) • Addition and Subtraction (3.3) • Constructing an ALU (B.5) • Multiplication and Division (3.4, 4.5) • Floating Point (3.6) • Coming Up: • Performance (Chapter 4)