Computer Arithmetic Ch 8

Similar documents
Computer Arithmetic Ch 8

Lecture 5. Computer Arithmetic. Ch 9 [Stal10] Integer arithmetic Floating-point arithmetic

Module 2: Computer Arithmetic

Organisasi Sistem Komputer

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

Divide: Paper & Pencil

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

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

Number Systems and Computer Arithmetic

Chapter 5 : Computer Arithmetic

CO212 Lecture 10: Arithmetic & Logical Unit

MIPS Integer ALU Requirements

FLOATING POINT NUMBERS

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

CPE300: Digital System Architecture and Design

Chapter 3: Arithmetic for Computers

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

Chapter 10 - Computer Arithmetic

Chapter 2 Data Representations

Floating Point Arithmetic

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

Computer Organisation CS303

ECE260: Fundamentals of Computer Engineering

COMPUTER ARITHMETIC (Part 1)

ECE232: Hardware Organization and Design

Floating-point representations

Data Representations & Arithmetic Operations

Floating-point representations

(+A) + ( B) + (A B) (B A) + (A B) ( A) + (+ B) (A B) + (B A) + (A B) (+ A) (+ B) + (A - B) (B A) + (A B) ( A) ( B) (A B) + (B A) + (A B)

COMPUTER ORGANIZATION AND ARCHITECTURE

COMPUTER ARCHITECTURE AND ORGANIZATION. Operation Add Magnitudes Subtract Magnitudes (+A) + ( B) + (A B) (B A) + (A B)

Inf2C - Computer Systems Lecture 2 Data Representation

C NUMERIC FORMATS. Overview. IEEE Single-Precision Floating-point Data Format. Figure C-0. Table C-0. Listing C-0.

Numeric Encodings Prof. James L. Frankel Harvard University

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

At the ith stage: Input: ci is the carry-in Output: si is the sum ci+1 carry-out to (i+1)st state

By, Ajinkya Karande Adarsh Yoga

Computer Architecture and Organization

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

Chapter 4. Operations on Data

Integer Multiplication. Back to Arithmetic. Integer Multiplication. Example (Fig 4.25)

COMP2611: Computer Organization. Data Representation

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

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

Topics. 6.1 Number Systems and Radix Conversion 6.2 Fixed-Point Arithmetic 6.3 Seminumeric Aspects of ALU Design 6.4 Floating-Point Arithmetic

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

Floating Point Numbers

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

UNIT - I: COMPUTER ARITHMETIC, REGISTER TRANSFER LANGUAGE & MICROOPERATIONS

Chapter Three. Arithmetic

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

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

Floating Point January 24, 2008

UNIT-III COMPUTER ARTHIMETIC

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other

Chapter 3 Arithmetic for Computers (Part 2)

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

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

Adding Binary Integers. Part 5. Adding Base 10 Numbers. Adding 2's Complement. Adding Binary Example = 10. Arithmetic Logic Unit

Chapter 3. Arithmetic Text: P&H rev

UNIT IV: DATA PATH DESIGN

Data Representation Type of Data Representation Integers Bits Unsigned 2 s Comp Excess 7 Excess 8

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

CHW 261: Logic Design

Arithmetic for Computers. Hwansoo Han

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

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

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

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

COMP 303 Computer Architecture Lecture 6

Thomas Polzer Institut für Technische Informatik

Finite arithmetic and error analysis

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

Floating Point Numbers. Lecture 9 CAP

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

COMPUTER ORGANIZATION AND DESIGN

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

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

Internal Data Representation

Foundations of Computer Systems

Number Systems. Both numbers are positive

Advanced Computer Architecture-CS501

Lecture 8: Addition, Multiplication & Division

EC2303-COMPUTER ARCHITECTURE AND ORGANIZATION

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

Computer Architecture Set Four. Arithmetic

CS222: Processor Design

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

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

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

CSE 141 Computer Architecture Summer Session Lecture 3 ALU Part 2 Single Cycle CPU Part 1. Pramod V. Argade

Arithmetic Processing

Floating-Point Arithmetic

Floating Point Arithmetic

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

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

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

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Arithmetic for Computers

CPS 104 Computer Organization and Programming

Transcription:

Computer Arithmetic Ch 8 ALU Integer Representation Integer Arithmetic Floating-Point Representation Floating-Point Arithmetic 1

Arithmetic Logical Unit (ALU) (2) (aritmeettis-looginen yksikkö) Does all work in CPU Rest is management! integer & floating point arithmetic's copy values from one register to another comparisons left and right shifts branch and jump address calculations load/store address calculations Control signals from CPU control unit what operation to perform and when 2

ALU Operations (5) Data from/to internal registers (latches) input data may have been copied from normal registers, or it may have come from memory output data may go to normal registers, or to memory Wait for maximum gate delay Result is ready Result may (also) be in flags Flags may cause an interrupt Fig. 8.1 (lipuke) 3

Integer Representation (8) Everything with 0 and 1 no plus/minus signs no decimal periods assumed on the right +32 +16 +8 +1 57 = 0011 1001 = 0x39 Unsigned integers Positive numbers easy normal binary form Negative numbers sign-magnitude two s complement sign bit hexadecimal presentation 3*16 +9*1 sign bit = MSB = most significant bit -57 = 1011 1001-57 = 1100 0111 complements +1 4

Twos Complement Most used Have space for 8 bits? use 7 bits for data and 1 bit for sign (kahden komplementti) +2 = 0000 0010 +1 = 0000 0001 0 = 0000 0000-1 = 1111 1111-2 = 1111 1110 just like in sign-magnitude or in one s complement (but presentation is different) ones complement: -0 = 1111 1111 5

Why Two s Complement Presentation? (4) Math is easy to implement subtraction becomes addition Have just one zero comparisons to zero easy Easy to expand to presentation with more bits simple circuit X-Y = X + (-Y) easy to do, simple circuit 57 = 0011 1001 = 0000 0000 0011 1001-57 = 1100 0111 = 1111 1111 1100 0111 sign extension 6

Why Two s Complement Presentation? (3) Range with n bits: -2 n-1 2 n-1-1 8 bits: -2 7 2 7-1 = -128 127 32 bits: -2 31 2 31-1 = -2 147 483 648 2 147 483 647 Overflow easy to recognise add positive & negative - no overflows add 2 positive/negative numbers if sign bit of result is different? overflow! 57 = 0011 1001 + 80 = 0101 0000 137 = 1000 1001 7

Why Two s Complement Presentation? (5) Addition easy if one or both operands negative treat them all as unsigned integers +3 = 0011 Same circuit works for both (except for overflow check) 13 = 1101 +1 = 0001 14 = 1110-3 = 1101 +1 = 0001-2 = 1110 1100 +1 1101 Digits represent 4 bit unsigned numbers Digits represent 4 bit two s complement numbers 8

Integer Arithmetic Operations Negation Addition Subtraction Multiplication Division X = -Y X = Y+Z X = Y-Z X = Y*Z X = Y / Z 9

Integer Negation (6) Step 1: negate all bits Step 2: add 1 Step 3: special cases ignore carry bit negate 0? 0 = 0000 0000 1111 1111 +1-0 = 1 0000 0000 check that sign bit really changes 57 = 0011 1001 1100 0110 +1 1100 0111 can not negate smallest negative -128 = 1000 0000 results in exception? bitwise not: 0111 1111 add 1: 1000 0000 10

Integer Addition and Subtraction (4) Normal binary addition 32 bit full adder? Ignore carry & monitor sign bit for overflow In case of SUB, complement 2nd operand 2 circuits addition complement Fig. 8.6 11

Integer Multiplication (4) Complex Operands 32 bits result 64 bits Just like you learned at school optimised for binary data it is easy to multiply with 0 or 1! Simpler case with unsigned numbers simple circuits adder shifter wires Fig. 8.7 12

Unsigned Multiplication Example (Fig. 8.8) 1st operand (kerrottava) operands result 2nd operand (kerroin) 13

Unsigned Multiplication Example (19) 13 * 11 =??? = 1000 1111 = 128+8+4+2+1 = 143 (Fig. 8.8) Overflow? No. M 1011 Result on left, multiplier on right! ADD ADD ADD SHIFT SHIFT SHIFT SHIFT C A Q 0 0000 1011 0010 0110 1000 1101 1111 1 0101 1101 0001 1110 1111 from C take next sumtake next sum result bit from A take skip next next sum sum just do SHIFT 14

Multiplication with Negative Values Multiplication for unsigned numbers does not work for negative numbers algorithm applies only for unsigned integer representation not the same case as with addition Could do it all with unsigned values change operands to positive values do multiplication with positive values negate result if needed OK, but can do better, I.e., faster 15

The Gist in Booth s Algorithm (7) Unsigned multiplication: addition for every 1 bit in multiplicand 5 * 7 Booth s algorithm: 0101 * 0111 combine all adjacent 1 s in multiplicand together, replace all additions by one subtraction and one addition (to result) 0101 + 01010 + 010100 = 100011 5 * 7 0101 * 0111 +0101000 0101 * (-0001 +1000) - 0101 = 100011 16

Booth s Algorithm (5) Current bit is the first of block of 1 s Sign bit extending Previous bit was at the last of block of 1 s Continuing block of 1 s Continuing block of 0 s (Fig. 8.12) 17

Booth s Algorithm for Twos Complement Multiplication operands Fig. 8.12 +/- arithmetic shift right Q -1 result 18

Booth s Algorithm Example (15) 7 * 3 =? = 0001 0101 = 21 M: 0111 Fig. 8.12 +/- A: Arithmetic Arithm Shift Right Arithm SHIFT SHIFT 1100 0101 0001 0000 Q: 1001 0100 0101 0011 10 1001 0010 1110 0011 1010 0100 01 Q -1 sign extended 1 bit of result 10 011 subtract ADD 00 just just SHIFT A-M SHIFT Carry bit was lost 19

Integer Division Like in school algorithm easy: new quotient digit 0 or 1 M register for dividend Q register for divisor & quotient (jakaja, osamäärä) Fig. 8.15 (jaettava) A register for (partial) remainder (jakojäännös) 20

21

Floating Point Representation -0.000 000 000 123 = -1.23 * 10-10 +0.123 = +1.23 * 10-1 +123.0 = +1.23 * 10 2 +123 000 000 000 000 = +1.23 * 10 14 + 14 1.23 sign exponent mantissa or significand (exponentti) (mantissa) 22

IEEE 32-bit Floating Point Standard IEEE Standard 754 + 14 1.1875 = 1.0011 sign exponent mantissa or significand 1 bit for sign, 1 -, 0 + I.e., Stored value S Sign value = (-1) S 23

IEEE 32-bit FP Standard + 15 1.1875 = 1.0011 sign exponent mantissa or significand 8 bits for exponent, 2 8-1= 127 biased form exponent = 5 store 5+127 = 132 =1000 0100 exponent = -1 store -1+127 = 126 = 0111 1110 exponent = 0 store 0+127 = 127 = 0111 1111 stored exponents 0 and 255 are special cases stored range: 1-254 true range: -126-127 24

IEEE 32-bit FP Standard (7) + 15 0.1875 = 0.0011 sign exponent mantissa or significand 23 bits for mantissa, stored so that 1) Binary point (.) is assumed just right of first digit 2) Mantissa is normalised, so that leftmost digit is 1 3) Leftmost (most significant) digit (1) is not stored (implied bit) 1/8 = 0.1250 1/16= 0.0625 0.1875 mantissa exponent 0.0011 15 1.100 12 1000 12 24 bit mantissa! 25

IEEE 32-bit FP Values 23 = +10111.0 * 2 0 = +1.0111 * 2 4 =? sign 1 bit 1.0 = +1.0000 * 2 0 =? sign 1 bit 4+127=131 0 1000 0011 011 1000 0000 0000 0000 0000 exponent 8 bits 0+127 = 127 0 0111 1111 000 0000 0000 0000 0000 0000 exponent 8 bits mantissa or significand 23 bits mantissa or significand 23 bits 26

IEEE 32-bit FP Values sign 1 bit 0 1000 0000 111 1000 0000 0000 0000 0000 exponent 8 bits mantissa or significand 23 bits X =? X = (-1) 0 * 1.1111 * 2 (128-127) = 1.1111 2 * 2 = (1+ 1/2 + 1/4 + 1/8 + 1/16) * 2 = (1 + 0.5 + 0.25 + 0.125+0.0625) * 2 = 1.9375 * 2 = 3.875 27

IEEE-754 Floating-Point Conversion http://babbage.cs.qc.edu/courses/cs341/ieee-754.html Christopher Vickery Computer Science Department at Queens College of CUNY (The City University of New York) 28

IEEE FP Standard Single Precision (SP) 32 bits Double Precision (DP) 64 bits (yksin- ja kaksinkertainen tarkkuus) Table 8.3 Special values -0, +,, NaN denormalized values Table 8.4 Not a Number 29

IEEE SP FP Range Range 8 bit exponent, effective range: -126 +127 range 2-126... 2 127 10-38... 10 38 Accuracy 23 bit mantissa, 24 bit effective mantissa change least significant digit in mantissa? 2 24 1.7 * 10-7 6 decimal digits 30

Floating Point Arithmetic (4) Relatively simple Done from registers with all bits implied bit included Add/subtract more complex than multiplication denormalize first one operand so that both have same exponent Multiplication/Division Table 8.5 handle mantissa and exponent separately 31

FP Add or Subtract (4) Check for zeroes trivial if one or both operands zero Align mantissas same exponent Add/subtract carry? shift right and add increase exponent Normalize result shift left, reduce exponent 1.234 10 4 + 4.444 10 6 0.01234 10 6 4.444 10 6 4.45634 10 6 4.45634 10 6 32

Exponent overflow above max Exponent underflow below min FP Special Cases Mantissa (significant) underflow in denormalizing may move bits too much right all significant bits lost? Exception Or ±? Mantissa (significant) overflow (ylivuoto) (alivuoto) Exception or zero? Oooops, lost data! Fix it result of adding mantissas may have carry 33

FP Multiplication (Division) (7) Check for zeroes Result 0, ±?? 3.000 10 4 * 4.444 10 6 Add exponents Subtract extra bias Report overflow/underflow + 10 10 Multiply (divide) mantissas Normalise * 13.332 10 10 1.3332 10 11 Round (pyöristä) 1.333 10 11 34

Guard bits Rounding (4) extra padding with zeroes used with computations only 4.444 10 6 4.44400 10 6 computations with more accuracy than data 2.0-1.9999 1.000000 2 1-0.1111111 2 1 = 1.000000 2 1-1.111111 2 0 6 bit mantissa 1.000000 2 1-0.111111 2 1 = 0.000001 2 1 = 1.000000 2-5 Different accuracy! 1.000000 00 2 1-0.111111 10 2 1 = 0.000000 10 2 1 = 1.000000 00 2-6 normalised Align mantissas 2 guard bits 35

Rounding Choices (4) 4 digit accuracy in memory? Nearest representable 3.1234 or -4.5678 3.123 or -4.568 Toward + 3.124 or -4.567 Toward - 3.123 or -4.568 Toward 0 3.123 or -4.567 36

IEEE and NaN outside range of finite numbers rules for arithmetic with NaN invalid operation (E.g., 0.0/0.0) can result to NaN or exception user control quiet NaN instead of exception Table 8.6 37

IEEE Denormalized Numbers (4) Problem: What to do when can not normalize any more? Exponent would underflow Answer: Denormalized representation smallest representable exponent reserved for this purpose mantissa is not normalized 6 decimal digit mantissa 0.003456 10-99 Smallest representable exponent 1.000000 10-99 0.000001 10-99 smallest (closest to zero) value is now much smaller than with normalized representation? 38

-- End of Chapter 8: Arithmetic -- FP unit Integer unit http://infopad.eecs.berkeley.edu/cic/die_photos/ 39