ECE291 Computer Engineering II Lecture 11 Josh Potts University of Illinois at Urbana- Champaign.

Slides:



Advertisements
Similar presentations
Physics for Games Programmers: Numerical Robustness (for Geometric Calculations) Christer Ericson Sony Computer Entertainment
Advertisements

ECE291 Computer Engineering II Lecture 19 Josh Potts University of Illinois at Urbana- Champaign.
COMP2130 Winter 2015 Storing signed numbers in memory.
ECE291 Computer Engineering II Lecture 24 Josh Potts University of Illinois at Urbana- Champaign.
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Floating Point Arithmetic.
Chapter 5 Floating Point Numbers. Real Numbers l Floating point representation is used whenever the number to be represented is outside the range of integer.
Representing Real Numbers Using Floating Point Notation Lecture 6 CSCI 1405, CSCI 1301 Introduction to Computer Science Fall 2009.
S. Mandayam/ CompArch2/ECE Dept./Rowan University Computer Architecture II: Specialized /02 Fall 2001 John L. Schmalzel Shreekanth Mandayam.
Floating Point Numbers
1/8/ L24 IEEE Floating Point Basics Copyright Joanne DeGroat, ECE, OSU1 IEEE Floating Point The IEEE Floating Point Standard and execution.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
1/8/ L24 IEEE Floating Point Basics Copyright Joanne DeGroat, ECE, OSU1 IEEE Floating Point The IEEE Floating Point Standard and execution.
ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.
Erik Jonsson School of Engineering and Computer Science FEARLESS Engineeringwww.utdallas.edu/~pervin EE/CE 2310 – HON/002 Introduction to Digital Systems.
1 Lecture 2  Complement  Floating Point Number  Character Encoding.
1 Number Systems Lecture 10 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
ECE291 Computer Engineering II Lecture 3 Josh Potts University of Illinois at Urbana- Champaign.
Floating Point Arithmetic
1/8/ L24 IEEE Floating Point Basics Copyright Joanne DeGroat, ECE, OSU1 IEEE Floating Point The IEEE Floating Point Standard and execution.
1 COMS 161 Introduction to Computing Title: Numeric Processing Date: November 08, 2004 Lecture Number: 30.
Computer Architecture Lecture 22 Fasih ur Rehman.
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Floating Point in Binary 1.Place Value Chart:
 Pg 75 #  Pg 83 #  Review HMWK. Multiplying and Dividing Real Numbers.
14/02/ Floating Point Representation Major: All Engineering Majors Authors: Autar Kaw, Charlie Barker Presented.
CS 232: Computer Architecture II Prof. Laxmikant (Sanjay) Kale Floating point arithmetic.
Representation of Data (Part II) Computer Studies Notes: chapter 19 Ma King Man.
Erik Jonsson School of Engineering and Computer Science FEARLESS Engineeringwww.utdallas.edu/~pervin EE/CE 2310 – HON/002 Introduction to Digital Systems.
Fixed-point and floating-point numbers Ellen Spertus MCS 111 October 4, 2001.
ECE291 Computer Engineering II Lecture 11 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Floating Point Arithmetic – Part I
FLOATING-POINT NUMBER REPRESENTATION
Floating Point. Binary Fractions.
Introduction to Numerical Analysis I
Nat 4/5 Computing Science Lesson 1: Binary
Fundamentals of Computer Science
Computer Architecture & Operations I
Floating Point Representations
Overview Introduction Data representation Fixed Point Representation
Numbers in a Computer Unsigned integers Signed magnitude
COSC 3330/6308 First Review Session
Expressible Numbers.
A Level Computing Component 2
PRESENTED BY J.SARAVANAN. Introduction: Objective: To provide hardware support for floating point arithmetic. To understand how to represent floating.
Chapter 6 Floating Point
Data Structures Mohammed Thajeel To the second year students
Data Representation and Arithmetic Algorithms
By: Briley Cooper, David Chaney, Josh Martin, and Mason Branscum
Systems Architecture I
EEL 3705 / 3705L Digital Logic Design
Floating Point Representation
The IEEE Floating Point Standard and execution units for it
Edward C. Jordan Memorial Offering of the First Course under the Indo-US Inter-University Collaborative Initiative in Higher Education and Research: Electromagnetics.
CSCI206 - Computer Organization & Programming
Floating Point Arithmetic
How to represent real numbers
COMS 161 Introduction to Computing
Data Representation and Arithmetic Algorithms
Faculty of Cybernetics, Statistics and Economic Informatics –
Representation of real numbers
Systems Architecture I
The IEEE Floating Point Standard and execution units for it
COMS 161 Introduction to Computing
Data Binary Arithmetic.
Chapter3 Fixed Point Representation
Floating Point Arithmetic
Lecture 9: Shift, Mult, Div Fixed & Floating Point
Presentation transcript:

ECE291 Computer Engineering II Lecture 11 Josh Potts University of Illinois at Urbana- Champaign

Josh PottsECE291 Outline Floating point arithmetic 80x87 Floating Point Unit

Josh PottsECE291 Floating-Point Numbers Components of a floating point number Sign: 0=pos(+); 1=neg(-) Exponent: (with constant bias added) Mantissa: 1 <= M < 2 Number = (1.Mantissa) * 2 (exponent-bias) Example: (decimal) = (binary) = * 2 3 (normalized)

Josh PottsECE291 Floating-point Format Precision Size Exp. Bias Mant. Mant. (bits) (bits) (bits) 1st Digit Single (7Fh) 23 Implied Double (3FFh) 52 Implied Extended (3FFFh) 63 Explicit

Josh PottsECE291 Converting to Floating-Point Form Convert the decimal number into binary Normalize the binary number Calculate the biased exponent Store the number in floating point format Example: = = x (7Fh) = (85h) 4. Sign = 0 Exponent = Mantissa = Note mantissa of a number 1.XXXX is the XXXX The 1. is an implied one-bit that is only stored in the extended precision form of the floating-point number as an explicit-one bit

Josh PottsECE291 Converting to Floating-Point Form Format Sign Exponent Mantissa Single (+) 7F+6 = 85h (8 bits) Implied 1. (23 bit) , ,1000,1000,0000,0000,0000 Double (+) 3FFh + 6 = 405h (11 bits) Implied 1. (52 bit) 0 100,0000, ,1000,1000,0000,…,0000 Extended (+) 3FFFh+6 = 4005h (15 bits) Explicit 1. (63 bit) 0 100,0000,0000, ,0100,0100,0000,…,

Josh PottsECE291 Examples

Josh PottsECE291 Special Representations Zero: –Exp = All Zero, Mant = All Zero NAN (not a number) an invalid floating-point result –Exp = All Ones, Mant non-zero + Infinity: –Sign = 0, Exp = All Ones, Mant = 0 - Infinity: –Sign = 1, Exp = All Ones, Mant = 0

Josh PottsECE291 Converting from Floating-Point Form (example) Sign = 1 Exponent = 1000,0011 Mantissa = 100,1001,0000,0000, = 1000, ,1111 (convert the biased exponent) x 2 4 (a normalized binary number) (a de-normalized binary number) ( a decimal number)

Josh PottsECE291 The 80x87 Floating Point Unit On-chip hardware for fast computation on floating point numbers FPU operations run in parallel with integer operations Historically implemented as separate chip – Coprocessor 80486DX-Pentium III contain their own internal and fully compatible versions of the CPU/FPU Exchange data though memory –Converts Single and Double to Extended-precision

Josh PottsECE291 Arithmetic Coprocessor Architecture Control unit –interfaces the coprocessor to the microprocessor-system data bus Numeric execution unit (NEU) –executes all coprocessor instructions NEU has eight-register stack –each register is 80-bit wide (extended-precision numbers) –data appear as any other form when they reside in the memory system –holds operands for arithmetic instructions and the results of arithmetic instructions –FSTSW AX ;the only instruction (not available for 8087) that allows direct communications between CPU and FPU through the AX register Other registers - status, control, tag, exception

Josh PottsECE291 Arithmetic Coprocessor FPU Registers The eight 80-bit data registers are organized as a stack As data items are pushed into the top register, previous data items move into higher-numbered registers, which are lower on the stack All coprocessor data are stored in registers in the 10-byte real format Internally, all calculations are done on the greatest precision numbers Instructions that transfer numbers between memory and coprocessor automatically convert numbers to and from the 10-byte real format

Josh PottsECE291 Sample 80x87 FPU Opcodes FADD: Addition FMUL: Multiplication FDIV: Division (divides the destination by the source) FDIVR: Division (divides the source by the destination) FSIN: Sine (uses radians) FCOS: Cosine (uses radians) FSQRT: Square Root FSUB: Subtraction FABS: Absolute Value FYL2X: Calculates Y * log 2 X(X) (Really) FYL2XP1: Calculates Y * log 2 X(X)+1 (Really)

Josh PottsECE291 Programming the FPU FPU Registers = ST(0).. ST(7) Format: OPCODE destination, source Restrictions: One register must be ST(0) ST=ST(0)=top of stack Use of ST(0) is implicit when not specified FINIT - Execute before starting to initialize FPU registers!

Josh PottsECE291 Programming the FPU (cont.) FLD MemVar –Load ST(0) with MemVar & –Push all other ST(i) to ST(i+1) for i=0..6 FSTP MemVar –Move top of stack to memory & –Push all other ST(i) to ST(i-1) for I = 1..7 FST MemVar –Move top of stack to memory –Leave result in ST(0) FSTP –Store Result and Pop FPU stack

Josh PottsECE291 FPU Programming Classical-Stack Format Instructions treat the coprocessor registers like items on the stack ST (the top of the stack) is the source operand ST(1), the second register, is the destination ST ST(1) fld 1fldpifadd Instructions Stack Contents

Josh PottsECE291 FPU Programming Memory Format The stack top (ST) is always the implied destination ST ST(1) fld m1 fld m2fadd m1 1.0 fstp m1 fst m2 m1 m DATA m1 REAL4 1.0 m2 REAL4 2.0.CODE …. fld m1 fld m2 fadd m1 fstp m1 fst m2

Josh PottsECE291 FPU Programming Register Format Instructions treat coprocessor registers as registers rather than stack elements –require two register operands; one of them must be the stack top (ST) ST ST(1) fadd st(1), st fadd st, st(2) fxch st(1) ST(2)

Josh PottsECE291 FPU Programming Register-Pop Format Coprocessor registers are treated as a modified stack –the source register must always be a stack top ST ST(1) faddp st(2), st 2.0 ST(2)

Josh PottsECE291 FPU Programming Timing Issues A coprocessor instruction following a processor instruction –coordinated by assembler for 8086 and 8088 –coordinated by processor on Pentium A processor instruction that accesses memory following a coprocessor instruction that accesses the same memory –for 8087 need include WAIT or FWAIT to ensure that coprocessor finishes before the processor begins –assembler is doing this automatically

Josh PottsECE291 Calculating the Area of a Circle MODEL SMALL.DATA RAD DD 2.34, 5.66, 9.33, 234.5, 23.4 AREA DD5 dup (?).CODE.STARTUP movsi, 0;source element 0 movdi, 0;destination element 0 mov cx, 5;count of 5 Main1: fld rad[si];radius to ST fmulst, st(0); square radius fldpi; pi to ST fmul; multiply ST = ST x ST(1) fstp AREA[di] inc si inc di loop Main1.EXIT END

Josh PottsECE291 Calculating Sqrt(x 2 + y 2 ) (Example of Using Code View).MODEL SMALL.STACK.DATA X real44.0 Y real43.0 Z real4?.CODE mainproc mov mov ds, ax finit fld X fldst(0) Fmul fld Y fldst(0) Fmul fadd fsqrt fstZ movax, 4C00h int21h mainendp