September, Saeid Nooshabadi. Overview IEEE 754 Standard COMP Microprocessors and Embedded Systems

Similar documents
3.5 Floating Point: Overview

September, 2003 Saeid Nooshabadi

Lecture 13: (Integer Multiplication and Division) FLOATING POINT NUMBERS

IEEE Standard 754 for Binary Floating-Point Arithmetic.

CS61C : Machine Structures

Precision and Accuracy

UC Berkeley CS61C : Machine Structures

xx.yyyy Lecture #11 Floating Point II Summary (single precision): Precision and Accuracy Fractional Powers of 2 Representation of Fractions

Floating Point Numbers. Lecture 9 CAP

UC Berkeley CS61C : Machine Structures

IEEE Standard 754 for Binary Floating-Point Arithmetic.

Chapter 3. Arithmetic for Computers

95% of the folks out there are completely clueless about floating-point.

UCB CS61C : Machine Structures

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

September, Saeid Nooshabadi. Review: Floating Point Representation COMP Single Precision and Double Precision

Floating Point Arithmetic

ecture 25 Floating Point Friedland and Weaver Computer Science 61C Spring 2017 March 17th, 2017

CS61C : Machine Structures

CS61C Floating Point Operations & Multiply/Divide. Lecture 9. February 17, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson)

CS61C : Machine Structures

Review 1/2 Big Idea: Instructions determine meaning of data; nothing inherent inside the data Characters: ASCII takes one byte

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

COMPUTER ORGANIZATION AND. Edition. The Hardware/Software Interface. Chapter 3. Arithmetic for Computers

COMP2611: Computer Organization. Data Representation

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

System Programming CISC 360. Floating Point September 16, 2008

Floating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. !

IEEE Standard for Floating-Point Arithmetic: 754

CS 61C: Great Ideas in Computer Architecture Floating Point Arithmetic

ECE232: Hardware Organization and Design

Computer Arithmetic Floating Point

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

CS61C : Machine Structures

Foundations of Computer Systems

Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.

Module 2: Computer Arithmetic

CS61C : Machine Structures

Computer Architecture and IC Design Lab. Chapter 3 Part 2 Arithmetic for Computers Floating Point

Signed Multiplication Multiply the positives Negate result if signs of operand are different

Floating Point Arithmetic

Numeric Encodings Prof. James L. Frankel Harvard University

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor.

Floating Point January 24, 2008

Integers and Floating Point

Computer (Literacy) Skills. Number representations and memory. Lubomír Bulej KDSS MFF UK

Introduction to Computers and Programming. Numeric Values

Divide: Paper & Pencil

Chapter Three. Arithmetic

COMP2121: Microprocessors and Interfacing. Number Systems

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor.

Chapter 2 Float Point Arithmetic. Real Numbers in Decimal Notation. Real Numbers in Decimal Notation

Instruction Set extensions to X86. Floating Point SIMD instructions

EE260: Logic Design, Spring n Integer multiplication. n Booth s algorithm. n Integer division. n Restoring, non-restoring

Inf2C - Computer Systems Lecture 2 Data Representation

Systems I. Floating Point. Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties

Chapter 3 Arithmetic for Computers

Organisasi Sistem Komputer

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Chapter 3 Arithmetic for Computers

Floating point. Today. IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Next time.

Arithmetic for Computers. Hwansoo Han

MIPS Integer ALU Requirements

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

Floating Point Numbers

Giving credit where credit is due

Giving credit where credit is due

CSCI 402: Computer Architectures. Arithmetic for Computers (3) Fengguang Song Department of Computer & Information Science IUPUI.

Exponential Numbers ID1050 Quantitative & Qualitative Reasoning

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

CS61c Midterm Review (fa06) Number representation and Floating points From your friendly reader

Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon

Data Representation Floating Point

Floating Point Arithmetic

FLOATING POINT NUMBERS

Floating-point representations

Floating-point representations

CS101 Introduction to computing Floating Point Numbers

Floating Point Puzzles The course that gives CMU its Zip! Floating Point Jan 22, IEEE Floating Point. Fractional Binary Numbers.

Data Representation Floating Point

Written Homework 3. Floating-Point Example (1/2)

Computer Architecture Chapter 3. Fall 2005 Department of Computer Science Kent State University

CS61C : Machine Structures

95% of the folks out there are completely clueless about floating-point.

M1 Computers and Data

Floating Point (with contributions from Dr. Bin Ren, William & Mary Computer Science)

Floating Point : Introduction to Computer Systems 4 th Lecture, May 25, Instructor: Brian Railing. Carnegie Mellon

CS 101: Computer Programming and Utilization

CO212 Lecture 10: Arithmetic & Logical Unit

Scientific Computing. Error Analysis

CS429: Computer Organization and Architecture

Floating Point Numbers

Floating Point Numbers

Recap from Last Time. CSE 2021: Computer Organization. It s All about Numbers! 5/12/2011. Text Pictures Video clips Audio

Chapter 4: Data Representations

The course that gives CMU its Zip! Floating Point Arithmetic Feb 17, 2000

Representing and Manipulating Floating Points

CS61C L10 MIPS Instruction Representation II, Floating Point I (6)

Floating Point Arithmetic. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Transcription:

COMP3221 lec20-fp-ii.1 COMP 3221 Microprocessors and Embedded Systems Lectures 20 : Floating Point Number Representation II http://www.cse.unsw.edu.au/~cs3221 September, 2003 Saeid@unsw.edu.au Overview IEEE 754 Standard Implied Hidden 1 Representation for 0 Decimal to Floating Point conversion, and vice versa Big Idea: Type is not associated with data ARM floating point instructions, registers COMP3221 lec20-fp-ii.2 Review: IEEE 754 Fl. Pt. Standard (#1/3) Summary (single precision): 31 30 23 22 S Exponent Significand 1 bit 8 bits 23 bits (-1) S x (1 + Significand) x 2 (Exponent-127) Double precision identical, except with exponent bias of 1023 Hidden 1 (implied) COMP3221 lec20-fp-ii.3 0 Review: IEEE 754 Fl. Pt. Standard (#2/3) Scientific notation in binary! COMP3221 lec20-fp-ii.4 ±1.F x 2 ±e Sign Magnitude for the fixed part (-1) s x 1.F x 2 ±e Hidden 1 of the significand (-1) s x 1. fffffffffffffffffffffff x 2 ±e Excess notation for the exponent (-1) s x 1.fffffffffffffffffffffff x 2exp - 127 Ordering the fields so integer compare works on FP

Representing the Significand Fraction In normalized form, fraction is either: 1.xxx xxxx xxxx xxxx xxxx xxx or 0.000 0000 0000 0000 0000 000 (for Zero) 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 Hidden Bit 1.xxx xxxx xxxx xxxx xxxx xxx becomes (1).xxx xxxx xxxx xxxx xxxx xxxx COMP3221 lec20-fp-ii.5 Comparison OK; subtracting 1 from both How differentiate from Zero in Trick Format? (1).0000... 000 =>. 0000... 0000 (0).0000... 000 =>. 0000... 0000 Solution: Reserve most negative (value 0) exponent to be only used for Zero; rest are normalized so prepend an implied 1 Convention is 0 Big 00000 0.00000 and not 1.00000 X2-127 0 > Big 00000 1.00000 x 2 Exp ( Big = 127 Sig=00000000 in 31 30 23 22 biased notation 0 0 00000000 00000000000000000000000 1 bit 8 bits 23 bits COMP3221 lec20-fp-ii.6 Understanding the Significand (#1/2) Method 1 (Fractions): In decimal: 0.340 10 => 340 10 /1000 10 => 34 10 /100 10 In binary: 0.110 2 => 110 2 /1000 2 = 6 10 /8 10 => 11 2 /100 2 = 3 10 /4 10 Advantage: less purely numerical, more thought oriented; this method usually helps people understand the meaning of the significand better Understanding the Significand (#2/2) Method 2 (Place Values): Convert from scientific notation In decimal: 1.6732 = (1x10 0 ) + (6x10-1 ) + (7x10-2 ) + (3x10-3 ) + (2x10-4 ) In binary: 1.1001 = (1x2 0 ) + (1x2-1 ) + (0x2-2 ) + (0x2-3 ) + (1x2-4 ) Interpretation of value in each position extends beyond the decimal/binary point Advantage: good for quickly calculating significand value; use this method for translating FP numbers COMP3221 lec20-fp-ii.7 COMP3221 lec20-fp-ii.8

Example: Converting Binary FP to Decimal 0 0110 1000 101 0101 0100 0011 0100 0011 Sign: 0 => positive Exponent: 0110 1000 two = 104 ten Bias adjustment: 104-127 = -23 Significand: 1 + 1x2-1 + 0x2-2 + 1x2-3 + 0x2-4 + 1x2-5 +... =1+2-1 +2-3 +2-5 +2-7 +2-9 +2-14 +2-15 +2-17 +2-22 +2-23 = 1.0 + 0.6661175 Represents: 1.6661175 ten *2-23 ~ 1.986*10-7 (about 2/10,000,000) COMP3221 lec20-fp-ii.9 Continuing Example: Binary to??? 0011 0100 0101 0101 0100 0011 0100 0011 Convert 2 s Comp. Binary to Integer: 2 29 +2 28 +2 26 +2 22 +2 20 +2 18 +2 16 +2 14 +2 9 +2 8 +2 6 + 2 1 +2 0 = 878,003,011 ten Convert Binary to Instruction: 0011 01 0 0 0 1 0 1 0101 0100 0011 0100 0011 ldrblo r4, [r5], #-835 Convert Binary to ASCII: 0011 0100 0101 0101 0100 0011 0100 0011 COMP3221 lec20-fp-ii.10 3 1 0 0 0 1 0 1 5 4 835 4 U C C Big Idea: Type not associated with Data 0011 0100 0101 0101 0100 0011 0100 0011 What does bit pattern mean: 1.986 *10-7? 878,003,011? 4UCC? ldrblo r4, [r5], #-835? Data can be anything; operation of instruction that accesses operand determines its type! Side-effect of stored program concept: instructions stored as numbers Power/danger of unrestricted addresses/ pointers: use ASCII as Fl. Pt., instructions as data, integers as instructions,... (Leads to security holes in programs) Converting Decimal to FP (#1/3) Simple Case: If denominator is an exponent of 2 (2, 4, 8, 16, etc.), then it s easy. Show IEEE 754 representation of -0.75-0.75 = -3/4-11 two /100 two -0.11 two /1.00 two = -0.11 two Normalized to -1.1 two x 2-1 (-1) S x (1 + Significand) x 2 (Exponent-127) (-1) 1 x (1 +.100 0000... 0000) x 2 (126-127) 1 0111 1110 100 0000 0000 0000 0000 0000 COMP3221 lec20-fp-ii.11 COMP3221 lec20-fp-ii.12

COMP3221 lec20-fp-ii.13 Converting Decimal to FP (#2/3) Not So Simple Case: If denominator is not an exponent of 2. Then we can t represent number precisely, but that s why we have so many bits in significand: for precision Once we have significand, normalizing a number to get the exponent is easy. So how do we get the Significand of a never ending number? Converting Decimal to FP (#3/3) Fact: All rational numbers have a repeating pattern when written out in decimal (eg 1/7 =0.142857142857 ) Fact: This still applies in binary as well (eg 1/111 =0.001001001 ) To finish conversion: COMP3221 lec20-fp-ii.14 Write out binary number with repeating pattern. Cut it off after correct number of bits (different for single vs double precision). Derive Sign, Exponent and Significand fields. Hairy Example (#1/2) How to represent 1/3 in IEEE 754? 1/3 = 0.33333 10 = 0.25 + 0.0625 + 0.015625 + 0.00390625 + 0.0009765625 + = 1/4 + 1/16 + 1/64 + 1/256 + 1/1024 + = 2-2 + 2-4 + 2-6 + 2-8 + 2-10 + = 0.0101010101 2 * 2 0 = 1.0101010101 2 * 2-2 (Normalized) Hairy Example (#2/2) 1/3 = 1.0101010101 2 * 2-2 Sign: 0 Exponent = -2 + 127 = 125 10 =01111101 2 Significand = 0101010101 0 0111 1101 0101 0101 0101 0101 0101 010 COMP3221 lec20-fp-ii.15 COMP3221 lec20-fp-ii.16

What s this stuff good for? Mow Lawn? Robot lawn mower: Robomow RL-800 Surround lawn, trees with perimeter wire Sense tall grass to spin blades faster: up to 5800 RPM Slow if senses object, stop if bumps US$700 Friendly Robotics of Even Yehuda, Israel, http://www.robotic-lawnmower.com COMP3221 lec20-fp-ii.17 COMP3221 lec20-fp-ii.18 Representation for +/- Infinity In FP, divide by zero should produce +/- infinity, not overflow. Why? OK to do further computations with infinity e.g., 1/(X/0) = (1/ ) = 0 is a valid Operation or, X/0 > Y may be a valid comparison (Ask math prof.) IEEE 754 represents +/- infinity Most positive exponent reserved for infinity Significands all zeroes Two Representation for 0! Represent 0? COMP3221 lec20-fp-ii.19 exponent all zeroes significand all zeroes too What about sign? +0: 0 00000000 00000000000000000000000-0: 1 00000000 00000000000000000000000 Why two zeroes? Helps in some limit comparisons Ask math prof. COMP3221 lec20-fp-ii.20 Special Numbers What have we defined so far? (Single Precision) Exponent Significand Object 0 0 0 0 nonzero??? 1-254 anything +/- fl. pt. # 255 0 +/- infinity 255 nonzero??? Professor Kahan had clever ideas; Waste not, want not We will talk about Exp=0,255 & Significand!=0 later

Recall: arithmetic in scientific notation Addition: 3.2 x 10 4 + 2.3 x 10 3 => common exp = 3.2 x 10 4 + 0.23 x 10 4 => add = 3.43 x 10 4 => normalize and round ~ 3.4 x 10 4 Multiplication: 3.2 x 10 4 x 2.3 x 10 5 Basic Fl. Pt. Addition Algorithm Much more difficult than with integers For addition (or subtraction) of X to Y (X<Y): (1) Compute D = Exp Y -Exp X (align binary point) (2) Right shift (1+Sig X ) D bits=>(1+sig X )*2 (ExpX-ExpY) (3) Compute (1+Sig X )*2 (ExpX - ExpY) + (1+Sig Y ) 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 = 3.2 x 2.3 x 10 9 = 7.36 x 10 9 ~ 7.4 x 10 9 (5) If result significand is 0, set exponent to 0 COMP3221 lec20-fp-ii.22 COMP3221 lec20-fp-ii.21 FP Addition/Subtraction Problems Problems in implementing FP add/sub: If signs differ for add (or same for sub), what will be the sign of the result? Question: How do we integrate this into the integer arithmetic unit? Answer: We don t! ARM s Floating Point Architecture (#1/4) Separate floating point instructions: Single Precision: fcmps, fadds, fsubs, fmuls, fdivs Double Precision: fcmpd, faddd, fsubd, fmuld, fdivd These instructions are far more complicated than their integer counterparts, so they can take much longer. COMP3221 lec20-fp-ii.23 COMP3221 lec20-fp-ii.24

ARM s Floating Point Architecture (#2/4) Problems: COMP3221 lec20-fp-ii.25 It s inefficient to have different instructions take vastly differing amounts of time. Generally, a particular piece of data will not change from FP to int, or vice versa, within a program. So only one type of instruction will be used on it. Some programs do no floating point calculations It takes lots of hardware relative to integers to do Floating Point fast ARM Floating Point Architecture (#3/4) ARM Solution: Make completely separate Coprocessors that handles only IEEE-754 FP. Coprocessor 10 (for SP) & 11 (for DP): Actually a Single hardware used differently for Single Precision and Double Precision contains 32 32-bit registers: S0 S31 Arithmetic instructions use this register set separate load and store: flds and fsts ( Float load Single Coprocessor 10, Float STore ) Double Precision: even/odd pair overlap one DP FP number: s0/s1 = d0, s2/s3 = d1,, s30/s31 =d15 separate double load and store: fldd and fstd ( Float load Double Coprocessor 11, Float STore ) COMP3221 lec20-fp-ii.26 ARM Floating Point Architecture (#4/4) ARM Solution: Processor: handles all the normal stuff Coprocessor 10 & 11: handles FP and only FP; more coprocessors? Yes, later Today, cheap chips may leave out FP HW (Example: Chip on Lab s DSLMU Board) Instructions to move data between main processor and coprocessors: fmsr (Sn = Rd), fmrs (Rd = Sn), etc. Check ARM instruction reference manual on CD-ROM for many, many more FP operations. COMP3221 lec20-fp-ii.27 In Conclusion Floating Point numbers approximate values that we want to use. IEEE 754 Floating Point Standard is most widely accepted attempt to standardize interpretation of such numbers ($1T) New ARM registers(s0-s31), instruct.: Single Precision (32 bits, 2x10-38 2x10 38 ): fcmps, fadds, fsubs, fmuls, fdivs Double Precision (64 bits, 2x10-308 2x10 308 ): fcmpd, faddd, fsubd, fmuld, fdivd Type is not associated with data, bits have no meaning unless given in context COMP3221 lec20-fp-ii.28