Number Representations

Similar documents
Divide: Paper & Pencil

Number Systems and Computer Arithmetic

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Floating Point Arithmetic

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

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

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

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

Foundations of Computer Systems

Floating Point January 24, 2008

COMP2611: Computer Organization. Data Representation

Floating-point representations

Floating-point representations

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

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

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

Data Representation Floating Point

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

Chapter Three. Arithmetic

Representing and Manipulating Floating Points

Data Representation Floating Point

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

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

System Programming CISC 360. Floating Point September 16, 2008

CO212 Lecture 10: Arithmetic & Logical Unit

CS 33. Data Representation (Part 3) CS33 Intro to Computer Systems VIII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Numeric Encodings Prof. James L. Frankel Harvard University

Representing and Manipulating Floating Points. Jo, Heeseung

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

Giving credit where credit is due

Chapter 3: Arithmetic for Computers

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

Giving credit where credit is due

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

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

Module 2: Computer Arithmetic

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

Representing and Manipulating Floating Points

Review: MULTIPLY HARDWARE Version 1. ECE4680 Computer Organization & Architecture. Divide, Floating Point, Pentium Bug

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

Divide: Paper & Pencil CS152. Computer Architecture and Engineering Lecture 7. Divide, Floating Point, Pentium Bug. DIVIDE HARDWARE Version 1

Inf2C - Computer Systems Lecture 2 Data Representation

Floating Point. CSE 238/2038/2138: Systems Programming. Instructor: Fatma CORUT ERGİN. Slides adapted from Bryant & O Hallaron s slides

Floating Point Numbers

CS429: Computer Organization and Architecture

EE 109 Unit 19. IEEE 754 Floating Point Representation Floating Point Arithmetic

Floating Point Numbers

Floating Point Numbers

ECE232: Hardware Organization and Design

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

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

Introduction to Computers and Programming. Numeric Values

Scientific Computing. Error Analysis

M1 Computers and Data

Floating Point Numbers. Lecture 9 CAP

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

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Computer Organization: A Programmer's Perspective

Today: Floating Point. Floating Point. Fractional Binary Numbers. Fractional binary numbers. bi bi 1 b2 b1 b0 b 1 b 2 b 3 b j

The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.

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

Representing and Manipulating Floating Points

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

CO Computer Architecture and Programming Languages CAPL. Lecture 15

3.5 Floating Point: Overview

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Topic Notes: Bits and Bytes and Numbers

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

Floating Point Numbers

Representing and Manipulating Floating Points. Computer Systems Laboratory Sungkyunkwan University

COMPUTER HARDWARE. Instruction Set Architecture

Up next. Midterm. Today s lecture. To follow

IEEE Standard for Floating-Point Arithmetic: 754

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

MIPS Integer ALU Requirements

EE 109 Unit 20. IEEE 754 Floating Point Representation Floating Point Arithmetic

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

Number Systems. Both numbers are positive

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

FLOATING POINT NUMBERS

Classes of Real Numbers 1/2. The Real Line

IEEE-754 floating-point

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Digital Computer Arithmetic ECE 666

Topic Notes: Bits and Bytes and Numbers

Floating Point Arithmetic

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

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

Floating Point Representation. CS Summer 2008 Jonathan Kaldor

VTU NOTES QUESTION PAPERS NEWS RESULTS FORUMS Arithmetic (a) The four possible cases Carry (b) Truth table x y

Computer Arithmetic Floating Point

CPE300: Digital System Architecture and Design

Numerical computing. How computers store real numbers and the problems that result

Computer Arithmetic Ch 8

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

Computer Arithmetic Ch 8

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

MACHINE LEVEL REPRESENTATION OF DATA

By, Ajinkya Karande Adarsh Yoga

Transcription:

Number Representations times XVII LIX CLXX -XVII D(CCL)LL DCCC LLLL X-X X-VII = DCCC CC III = MIII X-VII = VIIIII-VII = III 1/25/02

Memory Organization Viewed as a large, single-dimension array, with an address. 0 1 2 3 4 5 6 8 bits of data 8 bits of data 8 bits of data 8 bits of data 8 bits of data 8 bits of data 8 bits of data A memory address is an index into the array "Byte addressing" means that the index points to a byte of memory.... 2

Memory Organization Bytes are convenient for character data, but most data items use larger "words" Memory can be viewed as array of 4-Bytes words. 0 4 8 12 32 bits of data 32 bits of data 32 bits of data 32 bits of data 2 32 bytes with byte addresses from 0 to 232-1 2 30 words with byte addresses 0, 4, 8,... 232-4 MIPS words are word aligned (two least significant bits of a word address are always 00). 3 PowerPC words need not be word aligned (but access to unaligned words may be slower).

Datapath width MIPS fixed-point registers are 32 bits wide It s called a 32-bit architecture Many architectures are growing to 64-bits. DEC Alpha has been 64-bits all along. 4

x86 History Year model data width address bits 1971 4004 4 1972 8008 8 14 1974 8080 8 16 1978 8086 16 20 1982 80286 16 24 1985 80386 32 32 1989 80486 32 32 1993 Pentium 32 32 1995 Pentium pro 32 36 physical, 46 virtual 2001 Itanium 64 64 5

Big Endian vs. Little Endian 4 bytes make up a word, but how?? Byte address of word is address of first byte. But where does this byte go?? 0 8 bits of data 1 8 bits of data 2 8 bits of data 3 8 bits of data 31 0 4 8 bits of data 31 0 5 8 bits of data 6 8 bits of data least-significant bit Big Endian least-significant bit Little Endian 6

Big Endian vs. Little Endian Big Endian proponents: IBM, SGI, Sun, Motorola, HP,... Little Endian proponents: DEC, Intel Some processors (e.g. PowerPC) provide both If you can figure out how to switch modes or get the compiler to issue Byte-reversed load s and store s Very annoying for writing portable code or for moving data between machines! 7

Binary Numbers Consider a 4-bit binary number Decimal Binary Decimal Binary 0 0000 4 0100 1 0001 5 0101 2 0010 6 0110 3 0011 Examples of binary arithmetic: 3 + 2 = 5 3 + 3 = 6 1 7 0111 1 1 0 0 1 1 0 0 1 1 + 0 0 1 0 + 0 0 1 1 0 1 0 1 0 1 1 0 8

What about negative integers? Desirable features of a number system... obvious representation of 0,1,2... uses adder for addition easy to recognize exceptions (like overflow) single value of 0 equal coverage of positive and negative numbers easy detection of sign easy negation 9

Some Alternatives Sign Magnitude -- MSB is sign bit -1 1001-5 1101 One s complement -- flip all bits to negate -1 1110-5 1010 Biased -- add constant (e.g. excess 8 ) -1 0111, 0 1000, 1 1001,..., 7 1111 10

Two s Complement Representation Positive numbers: normal binary representation Negative numbers: flip bits (0 1), then add 1 11 Decimal -8-7 -6-5 -4-3 -2-1 0 1 2 3 4 5 6 7 Two s Complement Binary 1000 1001 1010 1011 1100 1101 1110 1111 0000 0001 0010 0011 0100 0101 0110 0111 Smallest 4-bit number: -8 Biggest 4-bit number: 7

Two s Complement Arithmetic Uses simple adder for + and - numbers 1 7 + (- 6) = 1 3 + (- 5) = -2 1 1 1 1 0 1 1 1 0 0 1 1 + 1 0 1 0 + 1 0 1 1 0 0 0 1 1 1 1 0 Decimal 2 s Complement Binary 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 Decimal -1-2 -3-4 -5-6 -7-8 2 s Complement Binary 1111 1110 1101 1100 1011 1010 1001 1000 12

Details of 2 s complement notation Negation flip bits and add 1. (Magic! Works for + and -) Might cause overflow. Extend sign when loading into large register +3 => 0011, 00000011, 0000000000000011-3 => 1101, 11111101, 1111111111111101 Overflow detection (need to raise exception when answer can t be represented) 0101 5 + 0110 6 1011-5??!!! 13

Overflow Detection 0 0 1 0 1 1 0 0 0 0 1 0 2 1 1 0 0-4 + 0 0 1 1 3 + 1 1 1 0-2 0 1 0 1 5 1 0 1 0-6 0 1 1 1 1 0 1 0 0 1 1 1 7 1 1 0 0-4 + 0 0 1 1 3 + 1 0 1 1-5 1 0 1 0-6 0 1 1 1 7 So how do we detect overflow? 14

Key Points Two s complement is standard +/- numbers. Achieves almost all of our goals. CPU clock speed is driven by adder delay Adder is used in loads, stores and branches as well as arithmetic. Thus, using a carry-lookahead adder is important! 15

Not all integers need a sign Some numbers are always non-negative Examples: addresses, character Bytes Wasteful to always have high-order bit 0. Hence, unsigned and signed operations. How are they different?? Add s and subtract s? Load s and stores? Shifts? 16

Binary fractions: Floating point numbers 1011 2 = 1x2 3 + 0x2 2 + 1x2 1 + 1x2 0 so... 101.01 2 = 1x2 2 + 0x2 1 + 1x2 0 + 0x2-1 + 1x2-2 example:.75 = 3/4 = 1/2 + 1/4 =.11 2 17

Recall Scientific Notation decimal point exponent sign +6.02 x 10 23 Mantissa radix (base) 18 Issues: Arithmetic (+, -, *, / ) Representation, Normal form Range and Precision Rounding Exceptions (e.g., divide by zero, overflow, underflow) Errors Properties ( negation, inversion, if A = B then A - B = 0 )

IEEE 754 Floating-Point Numbers Single precision representation of (-1) S 2 E-127 (1.M) sign bit 1 8 23 S E M exponent: excess 127 binary integer (actual exponent is e = E - 127) mantissa: (but leading 1 is omitted) 0 = 0 00000000 00... 0-1.5 = 1 01111111 10... 0 325 = 101000101 = 1.01000101 x 2 8 = 0 10000111 01000101000000000000000.02 =.0011001101100... = 1.1001101100... x 2-3 = 0 01111100 1001101100... range of about 2 X 10-38 to 2 X 10 38 special representation of 0 (E = 00000000) some extra values also carefully defined: denormalized numbers (no hidden 1 ) for very small numbers Not A Number (NAN) for results like divide-by-zero, etc. 19

Double Precision Floating Point in IEEE 754 sign 1 11 20 S E M 32 M exponent: excess 1023 binary integer actual exponent is e = E - 1023 mantissa: hidden integer bit: 1.M N = (-1) S 2 E-1023(1.M) 52 (+1) bit mantissa range of about 2 X 10-308 to 2 X 10 308 20

How do you compare numbers? 0 0 00000000 0000000000 1.5 * 2-100 0 00011011 1000000000 1.75 * 2-100 0 00011011 1100000000 1.5 * 2 100 0 11100011 1000000000 1.75*2 100 0 11100011 1100000000 Does this work with negative numbers, as well? 21

Floating Point Addition How do you add in scientific notation? 9.962 x 10 4 + 5.231 x 10 2 Basic Algorithm 1. Align 2. Add 3. Normalize 4. Round Not exact Usually, rounding throws away bits at the end. Subtracting two nearly-equal numbers doesn t lose bits, but answer doesn t have as many significant bits. 22

Floating Point Multiplication How do you multiply in scientific notation? (9.9 x 10 4 )(5.2 x 10 2 ) = 5.148 x 10 7 Basic Algorithm 1. Add exponents 2. Multiply 3. Normalize 4. Round 5. Set Sign 23

Floating Point Accuracy Extremely important in scientific calculations Very tiny errors can accumulate over time IEEE 754 has four rounding modes always round up (toward + ) always round down (toward - ) truncate (i.e. round towards zero) round to nearest => in case of tie, round to nearest even Requires extra bits in intermediate representations 24

Extra Bits for FP Accuracy Guard bits -- bits to the right of the least significant bit of the significand computed for use in normalization (could become significant at that point) and rounding. IEEE 754 has three extra bits and calls them guard, round, and sticky. 25

Floating point anomalies Suppose huge/tiny > 2 53 tiny + (huge huge) = tiny + 0 = tiny (tiny + huge) huge = huge huge = 0 Addition is not associative! IEEE 754 requires it to be commutative. Sometimes, compilers rearrange code, producing different results. May depend on language or compiler options. Small changes can ultimately have a big effect. e.g., whether there is a divide-by-zero exception 26

27 Java floating point Java Virtual Machine is exactly defined Operations give same answer on all machines But some machines have hardware to give more accurate answers Intel x86 uses 80-bit floating-point registers PowerPC uses extra-long register for FMA Result can be 2x speedup on some calculations To comply with JVM, extra instructions are needed to dumb down the answers! Result is slower code and less accurate answers (Java Grande group is exploring these issues)

Computer of the day Univac I first commercial computer ( 51)... Designed by Eckert & Mauchley (creators of ENIAC) Only 8 tons (ENIAC was 20 tons). Clock speed 2.25 MHz. Mercury delay line memory. 1 st machine with interrupts. 48 machines built priced $1M to $1.5M In 50 s, Univac was synonymous with computer... and first fights over intellectual property E&M applied for patent in 47 U. of P. dean said university should get patent E&M were fired or quit Lawsuit in 60 s, Honeywell v. Sperry Rand over patents 164 cubic feet of evidence Decision: Atanasoff (Iowa State) invented computer in 30 s. 28