DOC PREVIEW
Berkeley COMPSCI 61C - Lecture Notes

This preview shows page 1-2-14-15-29-30 out of 30 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS61C Floating Point Operations & Multiply/Divide Lecture 9Review 1/2Review 2/2: Floating Point RepresentationOutlineFloating Point BasicsOrder 3 Fields in a Word?How Stuff More Precision into Fraction?How differentiate from Zero in Trick Format?Negative Exponent?Example: Converting Fl. Pt. to DecimalSlide 11Basic Fl. Pt. Addition AlgorithmMIPS Floating Point ArchitectureAdministrivia“What’s This Stuff Good For?”Special IEEE 754 Symbols: InfinityGreedy Kahan: what else can I put in?Slide 18MULTIPLY (unsigned): Terms, ExampleMultiply by Power of 2 via Shift LeftDivide: Terms, Review Paper & PencilExample with Fl Pt, Multiply, Divide?MIPS code for first piece: initilialize, x[][]MIPS code for second piece: z[][], y[][]MIPS code for last piece: add/mul, loopsFloating Point Fallacies: Add Associativity?Shift Right Arithmetic; Divide by 2???Floating Point Fallacy: Accuracy optional?New MIPS arithmetic instructions“And in Conclusion..” 1/1cs 61C L9 FP.1Patterson Spring 99 ©UCBCS61CFloating Point Operations & Multiply/Divide Lecture 9February 17, 1999Dave Patterson (http.cs.berkeley.edu/~patterson)www-inst.eecs.berkel ey.edu/~cs61c/schedule.htmlcs 61C L9 FP.2Patterson Spring 99 ©UCBReview 1/2°Big Idea: Instructions determine meaning of data; nothing inherent inside the data °Characters: ASCII takes one byte•MIPS support for characters: lbu, sb°C strings: Null terminated array of bytes°Floating Point Data: approximate representation of very large or very small numbers in 32-bits or 64-bits•IEEE 754 Floating Point Standard•Driven by Berkeley’s Professor Kahancs 61C L9 FP.3Patterson Spring 99 ©UCBReview 2/2: Floating Point Representation°Single Precision and Double Precision031S Exponent30 23 22Significand1 bit 8 bits 23 bits°(-1)S x (1+Significand) x 2(Exponent-Bias)031S Exponent30 20 19Significand1 bit 11 bits 20 bitsSignificand (cont’d)32 bitscs 61C L9 FP.4Patterson Spring 99 ©UCBOutline°Fl. Pt. Representation, a little slower°Floating Point Add/Sub°MIPS Floating Point Support°Kahan crams more in 754: Nan, °Administrivia, “What’s this stuff Good for”°Multiply, Divide°Example: C to Asm for Floating Point°Conclusioncs 61C L9 FP.5Patterson Spring 99 ©UCBFloating Point Basics°Fundamentally 3 fields to represent Floating Point Number•Normalized Fraction (Mantissa/Significand)•Sign of Fraction•Exponent•Represents (-1)S x (Fraction) x 2Exponent where 1 <= Fraction < 2 (i.e., normalized)°If number bits left-to-right s1, s2, s3, ... then represents number(-1)Sx(1+(s1x2-1)+(s2x2-2)+(s3x2-3)+...)x 2Exponentcs 61C L9 FP.6Patterson Spring 99 ©UCBOrder 3 Fields in a Word?°“Natural”: Sign, Fraction, Exponent?•Problem: If want to sort using integer operations, won’t work: • 1.0 x 220 vs. 1.1 x 210 ; latter looks bigger! 0 10000 10100 0 11000 01010°Exponent, Sign, Fraction?•Need to get sign first, since negative < positive°Therefore order is Sign Exponent Fractioncs 61C L9 FP.7Patterson Spring 99 ©UCBHow Stuff More Precision into Fraction?°In normalized form, so fraction is either: 1.xxx xxxx xxxx xxxx xxxx xxxor0.000 0000 0000 0000 0000 000°Trick: If hardware automatically places 1 in front of binary point of normalized numbers, then get 1 more bit for the fraction, increasing accuracy “for free” 1.xxx xxxx xxxx xxxx xxxx xxxbecomes (1).xxx xxxx xxxx xxxx xxxx xxxx•Comparison OK; “subtracting” 1 from bothcs 61C L9 FP.8Patterson Spring 99 ©UCBHow differentiate from Zero in Trick Format?°1.0000 ... 000 => . 0000 ... 0000°Solution: Reserve most negative exponent to be only used for Zero; rest are normalized so prepend a 1°Convention is0 -Big 000000 > -Big 00000=> 0.00000=> 1.00000 x 2Expcs 61C L9 FP.9Patterson Spring 99 ©UCB°Instead, pick notation 0000 0000 is most negative, 1111 1111 is most positive•Called Biased Notation; bias subtracted to get number•127 in Single Prec. (1023 D.P.)•Zero is 0 0000 0000 0...0 0000Negative Exponent?°2’s comp? 1.0 x 2-1 v. 1.0 x2+1 (1/2 v. 2)•This notation using integer compare of 1/2 v. 2 makes 1/2 look greater than 2!0 1111 1111 000 0000 0000 0000 0000 00000 0000 0001 000 0000 0000 0000 0000 00001/22-127 0000 0000-126 0000 0001...-1 0111 1110 0 0111 1111 +1 1000 0000 ...+127 1111 1110 +128 1111 1111cs 61C L9 FP.10Patterson Spring 99 ©UCBExample: Converting Fl. Pt. to Decimal°(-1)S x (1+Significand) x 2(Exponent-Bias) °Sign: 0 => (-1)0 = 1 => positive°Exponent: 0110 1000two = 104ten•Bias adjustment: 104 - 127 = -23•Represents 2-23°Fraction:•Exponent not most negative (!= 0000 0000)so prepend a 1•1.101 0101 0100 0011 0100 00100 0110 1000 101 0101 0100 0011 0100 0010cs 61C L9 FP.11Patterson Spring 99 ©UCBExample: Converting Fl. Pt. to Decimal°Significand: 1 + (s1x2-1) + (s2x2-2) + ...•1+2-1+2-3 +2-5 +2-7 +2-9 +2-14 +2-15 +2-17 +2-22= 1+ 1/2 + 1/8 + 1/32 +1/128 + 1/512 + 1/16384 + 1/32768 + 1/131072 + 1/4194304 •Mutiply fractions by 4194304 (GCD) for sum= 1.0 + (2097152 + 524288 + 131072 + 32768 + 8192 + 256 + 128 + 32 + 1)/4194304 = 1.0 + (2793889)/4194304 = 1.0 + 0.66612°Bits represent: +1.66612ten*2-13~ +2.034*10-40 0110 1000 101 0101 0100 0011 0100 0010cs 61C L9 FP.12Patterson Spring 99 ©UCBBasic Fl. Pt. Addition AlgorithmFor addition (or subtraction) of X to Y (X<Y):(1) Compute D = ExpY - ExpX (align binary point)(2) Right shift (1+SigX) D bits=>(1+SigX)*2(ExpX-ExpY)(3) Compute (1+SigX)*2(ExpX - ExpY) + (1+SigY)Normalize if necessary; continue until MS bit is 1 (4) Too small (e.g., 0.001xx...) left shift result, decrement result exponent (4’) Too big (e.g., 101.1xx…) right shift result, increment result exponent(5) If result significand is 0, set exponent to 0cs 61C L9 FP.13Patterson Spring 99 ©UCBMIPS Floating Point Architecture°Single Precision, Double Precision versions of add, subtract, multiply, divide, compare•Single add.s, sub.s, mul.s, div.s, c.lt.s •Double add.d, sub.d, mul.d, div.d, c.lt.d °Registers?•Simplest solution: use existing registers•Normally integer and Fl.Pt. ops on different data, for performance could have separate registers•MIPS adds 32 32-bit Fl. Pt. reg: $f0, $f1, $f2 ...,•Thus need Fl. Pt. data transfers: lwc1, swc1 •Double Precision? Even-odd pair of registers ($f0#$f1) act as 64-bit register: $f0, $f2, $f4, ...cs 61C L9 FP.14Patterson Spring 99 ©UCBAdministrivia°Readings: 4.8 (skip HW), 3.9°5th


View Full Document

Berkeley COMPSCI 61C - Lecture Notes

Documents in this Course
SIMD II

SIMD II

8 pages

Midterm

Midterm

7 pages

Lecture 7

Lecture 7

31 pages

Caches

Caches

7 pages

Lecture 9

Lecture 9

24 pages

Lecture 1

Lecture 1

28 pages

Lecture 2

Lecture 2

25 pages

VM II

VM II

4 pages

Midterm

Midterm

10 pages

Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?