King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.

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.
Lecture 11 Oct 12 Circuits for floating-point operations addition multiplication division (only sketchy)
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.
CSCE 212 Chapter 3: Arithmetic for Computers Instructor: Jason D. Bakos.
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
CENG536 Computer Engineering department Çankaya University.
Lecture 16: Computer Arithmetic Today’s topic –Floating point numbers –IEEE 754 representations –FP arithmetic Reminder –HW 4 due Monday 1.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
COMP3221: Microprocessors and Embedded Systems Lecture 14: Floating Point Numbers Lecturer: Hui Wu Session 2, 2004.
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.
1 Ó1998 Morgan Kaufmann Publishers Chapter 4 計算機算數.
L11 – Floating Point 1 Comp 411 – Fall /21/2009 Floating-Point Arithmetic Reading: Study Chapter 3.5 Skim if ((A + A) - A == A) { SelfDestruct()
Integer Arithmetic Floating Point Representation Floating Point Arithmetic Topics.
1 Module 2: Floating-Point Representation. 2 Floating Point Numbers ■ Significant x base exponent ■ Example:
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
CS/COE0447 Computer Organization & Assembly Language
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Nizamettin AYDIN
CEN 316 Computer Organization and Design Computer Arithmetic Floating Point Dr. Mansour AL Zuair.
Ellen Spertus MCS 111 October 11, 2001 Floating Point Arithmetic.
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.
S. Rawat I.I.T. Kanpur. Floating-point representation IEEE numbers are stored using a kind of scientific notation. ± mantissa * 2 exponent We can represent.
Floating Point (a brief look) We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large numbers,
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 5 Unsigned integer and floating point.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /14/2013 Lecture 16: Floating Point Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
9.4 FLOATING-POINT REPRESENTATION
Lecture 9: Floating Point
Floating Point Representation for non-integral numbers – Including very small and very large numbers Like scientific notation – –2.34 × –
Conversion to Larger Number of Bits Ex: Immediate Field (signed 16 bit) to 32 bit Positive numbers have implied 0’s to the left. So, put 16 bit number.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
FLOATING POINT ARITHMETIC P&H Slides ECE 411 – Spring 2005.
Computer Architecture Lecture 22 Fasih ur Rehman.
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.
CSE 340 Simulation Modeling | MUSHFIQUR ROUF CSE340:
King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.
Computer Architecture Lecture 11 Arithmetic Ralph Grishman Oct NYU.
10/7/2004Comp 120 Fall October 7 Read 5.1 through 5.3 Register! Questions? Chapter 4 – Floating Point.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
Computer Organization & Design 计算机组成与设计 Weidong Wang ( 王维东 ) College of Information Science & Electronic Engineering 信息与通信工程研究所 Zhejiang.
Floating Point Arithmetic – Part I
Floating Point Representations
Morgan Kaufmann Publishers Arithmetic for Computers
Computer Architecture & Operations I
Lecture 9: Floating Point
Floating-Point Arithmetic
Floating Point Number system corresponding to the decimal notation
Floating-Point Arithmetic
CS/COE0447 Computer Organization & Assembly Language
Arithmetic for Computers
Lecture 10: Floating Point, Digital Design
Number Representations
Floating Point Arithmetic
Computer Arithmetic Multiplication, Floating Point
October 17 Chapter 4 – Floating Point Read 5.1 through 5.3 1/16/2019
Digital System Design II 数字系统设计2
Chapter 3 Arithmetic for Computers
Morgan Kaufmann Publishers Arithmetic for Computers
Floating Point Faculty of Information Technology University of Petra
Number Representations
Floating Point Arithmetic
Presentation transcript:

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 1 COE 308 Floating Point

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 2 COE 308 The World is not just Integers … ten (π) … ten (e) ten or 1.0 ten x ,155,760,000 ten or ten x 10 9 Scientific Notation: A.AAAAA x 10 yyyy ten x ten x Correct Normalized Notation Incorrect (un-normalized) notation ten x ten x 10 -8

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 3 COE 308 Floating Point Scientific Notation in binary: 1.XXXXXXXXX. 2 yyyyyyy Representation: Sign: S Exponent: E Significand: F (-1) S x (1.0 + F) x 2 E 1.0 > F ≥ 0

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 4 COE 308 Floating Point Representation SignExponent Significand:F GOAL  Quickly compare two FP numbers By considering them unsigned integers Options: Significand: Sign + Magnitude Two’s Complement Exponent: Sign + Magnitude Exponent Biased Exponent Significand:F Two’s Complement Sign + Magnitude

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 5 COE 308 Floating Point Representation - Two’s Complement - Example: Consider the following two numbers: A = 1.32 x 2 17 B = x 2 17 A = x 2 17 B = x 2 17 B = x 2 17 in 2’s complement representation A B Although in fact A > B because A>0 and B A if we consider them as two 32-bits unsigned integers. Two’s Complement Representation Unsuitable for Quickly comparing two FP numbers

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 6 COE 308 Floating Point Representation - Sign + Magnitude - A > B because of the sign bit. In Sign + Magnitude representation, the two numbers A = 1.32 x 2 17 and B = x 2 17 will be represented as follows: A B Sign + Magnitude Representation suitable for Quickly comparing two FP numbers

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 7 COE 308 How about the Exponent - Two’s Complement - In previous examples, A and B exponents were positive. How about if one of the exponents is negative? Example:A = 1.32 x and B = 1.22 x 2 17 Let’s represent the exponent in two’s complement representation A B Although in fact A B Exponent Two’s Complement Representation Unsuitable for Quickly comparing two FP numbers

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 8 COE 308 How about the Exponent - Biased Representation - In a biased representation, we add an offset to the exponent so that: The lowest negative exponent is represented with the value ONE ( ) If a number K = k 1. 2 e  E = e + bias For Single Precision, bias = 127 and for Double Precision, bias = A E = = 110 B E = = 144 A > B because of the biased representation of exponents Biased Representation Suitable

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 9 COE 308 Floating Point Representation - Summary - Sign:SExponent:ESignificand:F Sign + Magnitude better than 2’s complement Exponent represented in a bias notation (-1) S x (1.0 + F) x 2 E-bias IEEE-754 Standard

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 10 COE 308 MIPS Floating Point Formats S:1 bitE: 8 bitsF: 23 bits Follows IEEE-754 floating point standard Single Precision S:1 bit E: 11 bitsF: 20 bits Double Precision F: 32 bits

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 11 COE 308 Conversion How to convert from decimal to FP ?

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 12 COE 308 Representation of Zero Zero is represented with: –Sign bit at 0 –Exponent field composed of all bits at 0 –Significand bits are too all at

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 13 COE 308 Two Issues with FP Overflow occurs when the exponent of the result is larger than the available bits for the exponent field Underflow occurs when the result is smaller than the smallest number that can be represented and will yield a significand of 0s.

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 14 COE 308 Representation of Exceptions Infinity –Represented as a number with an exponent of 255 (Single Precision) or 2047 (Double Precision) –The sign determines whether it is ±    NaN: Not a Number. Used to represent errors and exceptions –Represented with maximum E and F≠0 –Result of exception like division by 0 or square root of negative number –Operation on a NaN will result in a NaN.

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 15 COE 308 Floating Point Addition Example: Add two numbers A = 1.85 x and B = 1.45 x How to proceed ? 1.85 x = x x = 1.45 x Need to align the two significands. Alignment of significands to have same exponents So that Addition becomes POSSIBLE Alignment of significands in binary is performed by shifts Smaller exponent number is shifted to the right

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 16 COE 308 Addition or Subtraction ? A and B may not be of the same sign Need also want to simply provide subtraction Need to Select between A and B to determine which one needs to be shifted right Need to Select between A and B to know which one needs to be complemented (2’s complement) Needs also to determine the sign of the result (whether to complement the result or not)

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 17 COE 308 Floating Point Addition Compare exponents Shift smaller number to the right (increment its exponent) until its exponent matches the larger exponent Complement one of the two operands (if needed) Add the two significands Loop to Normalize the result –Shift (left/right) to normalize the result –Detect overflow/underflow –Round the significand to the appropriate number of bits Complement the result (if needed)

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 18 COE 308 Floating Point Addition Circuit - complement + Sign Determination Unit Normalization and Rounding complement Exponent Compare Unit Shift

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 19 COE 308 Floating Point Multiplication Add the two biased exponents Subtract one time a bias to get a biased exponent –Because E 1 = e 1 + bias and E 2 = e 2 + bias –E 1 + E 2 = e 1 + e 2 + 2x bias Multiply the significands Loop to Normalize the result –Shift (left/right) to normalize the result –Detect overflow/underflow –Round the significand to the appropriate number of bits Set the sign of the product

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 20 COE 308 Floating Point Multiplication Circuit + Sign Determination Unit Normalization and Rounding Exponent Addition Unit Bias - Integer Multiplication Circuit

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 6 – Floating Point 21 COE 308 Floating Point Instructions in MIPS 32 Floating Point Registers $f0, …, $f31 add.s, sub.s, mul.s and div.s: single precision add.d, sub.d, mul.d and div.d: double precision lwc1, swc1: load/store fp to/from memory bc1t, bc1f: branch if FP cond true/false c.lt.s, c.lt.d: compare single/double precision.