Lecture 16: Computer Arithmetic Today’s topic –Floating point numbers –IEEE 754 representations –FP arithmetic Reminder –HW 4 due Monday 1.

Slides:



Advertisements
Similar presentations
Spring 2013 Advising Starts this week! CS2710 Computer Organization1.
Advertisements

Fixed Point Numbers The binary integer arithmetic you are used to is known by the more general term of Fixed Point arithmetic. Fixed Point means that we.
Chapter Three.
Computer Organization CS224 Fall 2012 Lesson 19. Floating-Point Example  What number is represented by the single-precision float …00 
Arithmetic in Computers Chapter 4 Arithmetic in Computers2 Outline Data representation integers Unsigned integers Signed integers Floating-points.
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Floating Point Numbers
Faculty of Computer Science © 2006 CMPUT 229 Floating Point Representation Operating with Real Numbers.
1 Lecture 9: Floating Point Today’s topics:  Division  IEEE 754 representations  FP arithmetic Reminder: assignment 4 will be posted later today.
Chapter 3 Arithmetic for Computers. Multiplication More complicated than addition accomplished via shifting and addition More time and more area Let's.
CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (2)
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 11: Floating Point Partially adapted from Computer Organization and Design, 4 th edition,
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
1 Lecture 10: FP, Performance Metrics Today’s topics:  IEEE 754 representations  FP arithmetic  Evaluating a system Reminder: assignment 4 due in a.
Morgan Kaufmann Publishers
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
Computer Science 210 Computer Organization Floating Point Representation.
CS/COE0447 Computer Organization & Assembly Language
Systems Architecture Lecture 14: Floating Point Arithmetic
February 26, 2003MIPS floating-point arithmetic1 Question  Which of the following are represented by the hexadecimal number 0x ? —the integer.
Ch. 2 Floating Point Numbers
Number Systems II Prepared by Dr P Marais (Modified by D Burford)
Computing Systems Basic arithmetic for computers.
ECE232: Hardware Organization and Design
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 10 Department of Computer Science and Software Engineering University of.
Data Representation in Computer Systems
Floating Point (a brief look) We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large numbers,
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /14/2013 Lecture 16: Floating Point Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
9.4 FLOATING-POINT REPRESENTATION
CSF 2009 Arithmetic for Computers Chapter 3. Arithmetic for Computers Operations on integers Addition and subtraction Multiplication and division Dealing.
Fixed and Floating Point Numbers Lesson 3 Ioan Despi.
Lecture 9: Floating Point
CSC 221 Computer Organization and Assembly Language
Floating Point Representation for non-integral numbers – Including very small and very large numbers Like scientific notation – –2.34 × –
Lecture 12: Integer Arithmetic and Floating Point CS 2011 Fall 2014, Dr. Rozier.
CDA 3101 Fall 2013 Introduction to Computer Organization
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
1 Lecture 10: Floating Point, Digital Design Today’s topics:  FP arithmetic  Intro to Boolean functions.
Chapter 3 Arithmetic for Computers. Chapter 3 — Arithmetic for Computers — 2 Arithmetic for Computers Operations on integers Addition and subtraction.
Floating Point Numbers Representation, Operations, and Accuracy CS223 Digital Design.
University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell CS352H: Computer Systems Architecture Lecture 6: MIPS Floating.
C OMPUTER O RGANIZATION AND D ESIGN The Hardware/Software Interface 5 th Edition Chapter 3 Arithmetic for Computers.
CS 224 Computer Organization Spring 2011 Arithmetic for Computers With thanks to M.J. Irwin, D. Patterson, and J. Hennessy for some lecture slide contents.
CSE 340 Simulation Modeling | MUSHFIQUR ROUF CSE340:
CS 232: Computer Architecture II Prof. Laxmikant (Sanjay) Kale Floating point arithmetic.
10/7/2004Comp 120 Fall October 7 Read 5.1 through 5.3 Register! Questions? Chapter 4 – Floating Point.
King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.
COMPUTER ORGANIZATION ARITHMETIC YASSER MOHAMMAD.
Floating Point Representations
Morgan Kaufmann Publishers Arithmetic for Computers
Computer Architecture & Operations I
Morgan Kaufmann Publishers Arithmetic for Computers
Lecture 9: Floating Point
Floating Point Number system corresponding to the decimal notation
CS 232: Computer Architecture II
CS/COE0447 Computer Organization & Assembly Language
Morgan Kaufmann Publishers
PRESENTED BY J.SARAVANAN. Introduction: Objective: To provide hardware support for floating point arithmetic. To understand how to represent floating.
Arithmetic for Computers
Lecture 10: Floating Point, Digital Design
ECE/CS 552: Floating Point
Computer Arithmetic Multiplication, Floating Point
October 17 Chapter 4 – Floating Point Read 5.1 through 5.3 1/16/2019
Chapter 3 Arithmetic for Computers
Morgan Kaufmann Publishers Arithmetic for Computers
Presentation transcript:

Lecture 16: Computer Arithmetic Today’s topic –Floating point numbers –IEEE 754 representations –FP arithmetic Reminder –HW 4 due Monday 1

Floating Point Representation for non-integral numbers –Including very small and very large numbers Like scientific notation ––2.34 × – × 10 –4 – × 10 9 In binary –±1.xxxxxxx 2 × 2 yyyy Types float and double in C normalized not normalized 2

Floating Point Standard Defined by IEEE Std Now almost universally adopted Two representations –Single precision (32-bit) –Double precision (64-bit) A standard notation enables easy exchange of data between machines and simplifies hardware algorithms – the IEEE 754 standard defines how floating point numbers are represented 3

IEEE Floating-Point Format S: sign bit (0  non-negative, 1  negative) Normalize significand: 1.0 ≤ |significand| < 2.0 –Always has a leading pre-binary-point 1 bit, so no need to represent it explicitly (hidden bit) –Significand is Fraction with the “1.” restored Exponent: excess representation: actual exponent + Bias –Ensures exponent is unsigned –Single: Bias = 127; Double: Bias = 1203 SExponentFraction single: 8 bits double: 11 bits single: 23 bits double: 52 bits 4

5 Single Precision Sign Exponent Fraction 1 bit 8 bits 23 bits SEF More exponent bits  wider range of numbers (not necessarily more numbers – recall there are infinite real numbers) More fraction bits  higher precision

Single-Precision Range Exponents and reserved Smallest value –Exponent:  actual exponent = 1 – 127 = –126 –Fraction: 000…00  significand = 1.0 –±1.0 × 2 –126 ≈ ±1.2 × 10 –38 Largest value –exponent:  actual exponent = 254 – 127 = +127 –Fraction: 111…11  significand ≈ 2.0 –±2.0 × ≈ ±3.4 ×

Double-Precision Range Exponents 0000…00 and 1111…11 reserved Smallest value –Exponent:  actual exponent = 1 – 1023 = –1022 –Fraction: 000…00  significand = 1.0 –±1.0 × 2 –1022 ≈ ±2.2 × 10 –308 Largest value –Exponent:  actual exponent = 2046 – 1023 = –Fraction: 111…11  significand ≈ 2.0 –±2.0 × ≈ ±1.8 ×

Floating-Point Example Represent –0.75 ––0.75 = (–1) 1 × × 2 –1 –S = 1 –Fraction = 1000…00 2 –Exponent = –1 + Bias Single: – = 126 = Double: – = 1022 = Single: …00 Double: …00 8

Floating-Point Example What number is represented by the single-precision float …00 –S = 1 –Fraction = 01000…00 2 –Fxponent = = 129 x = (–1) 1 × ( ) × 2 (129 – 127) = (–1) × 1.25 × 2 2 = –5.0 9

10 Details The number “0” has a special code so that the implicit 1 does not get added: the code is all 0s (it may seem that this takes up the representation for 1.0, but given how the exponent is represented, we’ll soon see that that’s not the case) The largest exponent value (with zero fraction) represents +/- infinity The largest exponent value (with non-zero fraction) represents NaN (not a number) – for the result of 0/0 or (infinity minus infinity)

11 More Details To simplify sort, sign was placed as the first bit For a similar reason, the representation of the exponent is also modified: in order to use integer compares, it would be preferable to have the smallest exponent as 00…0 and the largest exponent as 11…1 This is the biased notation, where a bias is subtracted from the exponent field to yield the true exponent IEEE 754 single-precision uses a bias of 127 (since the exponent must have values between -127 and 128)…double precision uses a bias of 1023 Final representation: (-1) S x (1 + Fraction) x 2 (Exponent – Bias)

Floating-Point Addition Consider a 4-digit decimal example –9.999 × × 10 –1 1. Align decimal points –Shift number with smaller exponent –9.999 × × Add significands –9.999 × × 10 1 = × Normalize result & check for over/underflow – × Round and renormalize if necessary –1.002 ×

Floating-Point Addition Now consider a 4-digit binary example – × 2 –1 + – × 2 –2 (0.5 + –0.4375) 1. Align binary points –Shift number with smaller exponent – × 2 –1 + – × 2 –1 2. Add significands – × 2 –1 + – × 2 -1 = × 2 –1 3. Normalize result & check for over/underflow – × 2 –4, with no over/underflow 4. Round and renormalize if necessary – × 2 –4 (no change) =

Floating-Point Multiplication Consider a 4-digit decimal example –1.110 × × × 10 –5 1. Add exponents –For biased exponents, subtract bias from sum –New exponent = 10 + –5 = 5 2. Multiply significands –1.110 × =  × Normalize result & check for over/underflow – × Round and renormalize if necessary –1.021 × Determine sign of result from signs of operands – ×

Floating-Point Multiplication Now consider a 4-digit binary example – × 2 –1 × – × 2 –2 (0.5 × –0.4375) 1. Add exponents –Unbiased: –1 + –2 = –3 –Biased: (– ) + (– ) = – – 127 = – Multiply significands – × =  × 2 –3 3. Normalize result & check for over/underflow – × 2 –3 (no change) with no over/underflow 4. Round and renormalize if necessary – × 2 –3 (no change) 5. Determine sign: +ve × –ve  –ve –– × 2 –3 = –

16 MIPS Instructions The usual add.s, add.d, sub, mul, div Comparison instructions: c.eq.s, c.neq.s, c.lt.s…. These comparisons set an internal bit in hardware that is then inspected by branch instructions: bc1t, bc1f Separate register file $f0 - $f31 : a double-precision value is stored in (say) $f4-$f5 and is referred to by $f4 Load/store instructions (lwc1, swc1) must still use integer registers for address computation

17 Code Example float f2c (float fahr) { return ((5.0/9.0) * (fahr – 32.0)); } (argument fahr is stored in $f12) lwc1 $f16, const5($gp) lwc1 $f18, const9($gp) div.s $f16, $f16, $f18 lwc1 $f18, const32($gp) sub.s $f18, $f12, $f18 mul.s $f0, $f16, $f18 jr $ra