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

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

Divide: Paper & Pencil

MIPS Integer ALU Requirements

Number Systems and Computer Arithmetic

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

Module 2: Computer Arithmetic

ECE232: Hardware Organization and Design

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

CPE300: Digital System Architecture and Design

COMP 303 Computer Architecture Lecture 6

By, Ajinkya Karande Adarsh Yoga

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

Chapter 5 : Computer Arithmetic

Organisasi Sistem Komputer

Chapter 3 Arithmetic for Computers (Part 2)

More complicated than addition. Let's look at 3 versions based on grade school algorithm (multiplicand) More time and more area

CPS 104 Computer Organization and Programming

Timing for Ripple Carry Adder

Chapter 3: Arithmetic for Computers

Computer Architecture and Engineering Lecture 7: Divide, Floating Point, Pentium Bug

ECE260: Fundamentals of Computer Engineering

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

Computer Arithmetic Ch 8

Computer Arithmetic Ch 8

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

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

9 Multiplication and Division

AT Arithmetic. Integer addition

CHW 261: Logic Design

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

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 3. Arithmetic for Computers Implementation

Floating Point Arithmetic

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

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

Chapter 3. Arithmetic Text: P&H rev

Review: MIPS Organization

CO212 Lecture 10: Arithmetic & Logical Unit

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

Foundations of Computer Systems

EECS150 - Digital Design Lecture 13 - Combinational Logic & Arithmetic Circuits Part 3

COMPUTER ARITHMETIC (Part 1)

Floating-point representations

Floating-point representations

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

Numeric Encodings Prof. James L. Frankel Harvard University

FLOATING POINT NUMBERS

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

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

COMPUTER ORGANIZATION AND DESIGN

Tailoring the 32-Bit ALU to MIPS

Chapter 4 Section 2 Operations on Decimals

CS/COE 0447 Example Problems for Exam 2 Spring 2011

ECE331: Hardware Organization and Design

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

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

Computer Architecture. Chapter 3: Arithmetic for Computers

Iterative Division Techniques COMPUTER ARITHMETIC: Lecture Notes # 6. University of Illinois at Chicago

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

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

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

Chapter 10 - Computer Arithmetic

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

University of Illinois at Chicago. Lecture Notes # 13

COMP2611: Computer Organization. Data Representation

UNIT-III COMPUTER ARTHIMETIC

Computer Architecture Set Four. Arithmetic

Homework 3. Assigned on 02/15 Due time: midnight on 02/21 (1 WEEK only!) B.2 B.11 B.14 (hint: use multiplexors) CSCI 402: Computer Architectures

D I G I T A L C I R C U I T S E E

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

Arithmetic for Computers. Hwansoo Han

Arithmetic Processing

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

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

5DV118 Computer Organization and Architecture Umeå University Department of Computing Science Stephen J. Hegner. Topic 3: Arithmetic

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

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

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

Inf2C - Computer Systems Lecture 2 Data Representation

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

NUMBER OPERATIONS. Mahdi Nazm Bojnordi. CS/ECE 3810: Computer Organization. Assistant Professor School of Computing University of Utah

Floating-Point Arithmetic

Floating Point Square Root under HUB Format

Floating Point Numbers

Chapter 2 Data Representations

Introduction to Computers and Programming. Numeric Values

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

Computer Organisation CS303

CS 101: Computer Programming and Utilization

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

Number Systems CHAPTER Positional Number Systems


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

Chapter 3. Arithmetic for Computers

EE878 Special Topics in VLSI. Computer Arithmetic for Digital Signal Processing

Arithmetic Logic Unit

Thomas Polzer Institut für Technische Informatik

Part III The Arithmetic/Logic Unit. Oct Computer Architecture, The Arithmetic/Logic Unit Slide 1

Data Representations & Arithmetic Operations

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

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

Transcription:

Back to Arithmetic Before, we did Representation of integers Addition/Subtraction Logical ops Forecast Integer Multiplication Integer Division Floating-point Numbers Floating-point Addition/Multiplication Integer Multiplication Recall decimal multiplication from grammar school (non negative) multiplicand 1000 base ten multiplier 1001 base ten partial 1000 products 0000 0000 1000 1001000 base ten CS/ECE 552 Lecture Notes: Chapter 4 1 CS/ECE 552 Lecture Notes: Chapter 4 2 Integer Multiplication Example (Fig 4.25) Convert to binary Use carry-save adders in a wallace tree n bits times m bits = n+m bits (32 + 32 = 64) Multiplicand Shift left 64 bits Example next (Figure 4.27) Multiplicand = 2 = 0010 Multiplier = 3 = 0011 Product = 6 = 0110 64-bit ALU Product Write Control test Multiplier Shift right 32 bits 64 bits CS/ECE 552 Lecture Notes: Chapter 4 3 CS/ECE 552 Lecture Notes: Chapter 4 4

Example (Fig. 4.26) Integer Multiplication Start Multiplier0 = 0 1. Test Multiplier0 Multiplier0 = 1 1a. Add multiplicand to product and place the result in Product register 2. Shift the Multiplicand register left 1 b 3. Shift the Multiplier register right 1 b No: < 32 repetition 32nd repetition? Yes: 32 repetitions Done Two optimizations observation: upper-half of 64 bits are all zero use 32-bit ALU and shift product right instead of multiplicand left (multiplier still goes right) observation: only half of product is used put multiplier in not-yet-used part of product CS/ECE 552 Lecture Notes: Chapter 4 5 CS/ECE 552 Lecture Notes: Chapter 4 6 Integer Multiplication Integer Multiplication Combinational multiplier 1000 * 1001 1000 1 1000 AND bits to get partial products 0 0000 ADD PPs in tree to get product 0 0000 Use carry-save addition: 3 to 2 reduction every step 1 1000 1001000 What about negative multiplicand and/or multiplier grammar school Booth s encoding Grammar school sign-prod = sign-mplicand XOR sign-mplier; negative = 0 if multiplicand < 0 {multiplicand = -multiplicand; negative++} if multiplier < 0 {multiplier = -multiplier; negative++} product = multiplicand*multiplier if negative == 1 product = -product CS/ECE 552 Lecture Notes: Chapter 4 7 CS/ECE 552 Lecture Notes: Chapter 4 8

Integer Multiplication Booth encoding -- mind bending like carry-lookahead Skipping over 9 s in decimal - look for beginning and end of 9 s 12345 Booth s Encoding In binary works for 1 s - 1 less than 2 we already are fast on zeroes * 09990 = -10 + 10000-123450 12345*10 +123450000 12345*10000 123326550 But in decimal only works for 9 s - 1 less than base (10) current bit bit to right info 1 0 start 1 s -1 1 1 middle of 1 s 0 0 1 end of 1 s +1 0 0 middle of 0 s 0 CS/ECE 552 Lecture Notes: Chapter 4 9 CS/ECE 552 Lecture Notes: Chapter 4 10 Booth s Encoding Booth Encoding -2k 1k 512 256 128 64 32 16 8 4 2 1 0 1 1 1 0 0 1 1 1 0 1 0 0 0 0 0-1 0 +1 0 0-1 +1-1 0 0 0 0-2 +2-1 +1 0-2048 + 1024 + 512 + 64 + 32 + 16 + 4-1*512 + 1*128 + -1*16 + 1*8 + -1*4-2*256 + 2 *64 + -1*16 + 1*4 1010 -> -6 8 bits = 11111010 -(-6) = 00000110 0110 -> +6 Boothenc = +1 0-1 - = +0-0 11111010 *0 = 0 1111010_ *- = 00001100 111010 *0 = 0 11010 *+ = 11010000 11011100 = -36 all equivalent CS/ECE 552 Lecture Notes: Chapter 4 11 CS/ECE 552 Lecture Notes: Chapter 4 12

Booth Encoding Redundant Representations negative multiplier 1010 = -6 1110 = -2 booth enc 000-0 0000110_ = 00001100 = +12 b * a 2 a 1 a 0 = (a 1 -a 2 )*b*2 2 + (a 0 -a 1 )*b*2 1 + (0-a 0 )*b*2 0 -a 2 *b*2 2 + (2*a 1 -a 1 )*b*2 1 + (2*a 0 -a 0 )*b*2 0 [a 2 *-2 2 + a 1 *2 1 + a 0 *2 0 ]!! Normally d 2 *b 2 + d 1 *b 1 + d * 0 b 0 ; b base, d i usually (0, 1,... base-1} Booth Encoding b = 2, d i = {-1, 0, +1} Carry-Save addition b = 2, d i = { 0, 1, 2, 3} 2-bit Booth Encoding b = 4, d i = {-2, -1, 0, +1, +2} CS/ECE 552 Lecture Notes: Chapter 4 13 CS/ECE 552 Lecture Notes: Chapter 4 14 2-bit Booth Encoding 2-bit Booth Encoding n-bit encoding retires n multiplier bits at a time Eg., 1 1 1 0 0 1 1 1 0 1 0 0 0 0 0-1 0 +1 0 0-1 +1-1 0 0 -------- 1 bit enc 0-2 +2-1 +1 0 -------- 2 bit enc For each partial product, mux controlled by multiplier digits -2-2 sc, shift left one bit -1-2 sc 0 +1 pass through +2 shift left one bit CS/ECE 552 Lecture Notes: Chapter 4 15 CS/ECE 552 Lecture Notes: Chapter 4 16

Integer Division divisor - 1000 dividend 1001010 - grammar school 1000)1001010( 1001 - quotient 1000 10 101 1010 Integer Division But hardware can t inspect to see if divisor fits, so Subtract if non-negative then set quotient to 1 else set quotient to 0, add back the divisor (or restore ) Figure Can do multiplication-like optimizations 1000 10 - remainder CS/ECE 552 Lecture Notes: Chapter 4 17 CS/ECE 552 Lecture Notes: Chapter 4 18 Integer Division Integer Division Non-restoring division - a key optimization in division Recall restoring division: divisor 1000, 2 sc 1... 11000 0010101 + 11000 -divisor*2 2 11101 => < 0 +01000 +divisor*2 2 00101 001010 next bit down +111000 -divisor*2 2 000010 (-d*2 2 + d*2 2 ) - d*2 1 CS/ECE 552 Lecture Notes: Chapter 4 19 CS/ECE 552 Lecture Notes: Chapter 4 20

Integer Division Integer Division Now non-restoring 0010101 + 11000 -divisor*2 2 11101 => < 0 111010 next bit down +001000 +divisor*2 1 000010 (-d*2 2 +d*2 1 ) == -d*2 1 But quotient bits are {1, 1} quotient bit = 1 if partial remainder is >= 0 (i.e., subtract) quotient bit = 1 if partial remainder is < 0 (i.e., add) convert the weird quotient into 2 sc for any 2 sc negative numbers: quotient bit = 1 if partial remainder and divisor are same sign quotient bit = 1 if partial remainder and divisor are opposite sign CS/ECE 552 Lecture Notes: Chapter 4 21 CS/ECE 552 Lecture Notes: Chapter 4 22 SRT Division and Pentium Bug Normalize so 1 <= dividend, divisor < 2 Use radix 4 for divisor base = 2 get 2 bits of quotient per iteration Use redundant quotient representation digits {-2, -1, 0, +1, +2} instead of {0,1,2,3} Pentium Bug partial-remainder = dividend loop { determine next quotient digit subtract quotient-digit*divisor from partial-remainder (CSA) shift over 2 bits (radix 4) } CS/ECE 552 Lecture Notes: Chapter 4 23 CS/ECE 552 Lecture Notes: Chapter 4 24

Pentium Bug Determine next quotient digit conceptually - a table-lookup into table[partial-remainder, divisor] guess next 2 quotient bits some part of the table is not accessible so optimized as don t cares in PLA But some of the don t cares (5) actually occur in practice! Pentium Bug Incomplete testing did not expose, since the algorithm self-corrects as long as the partial-remainder is in range incorrect quotient for some dividend, divisor pairs 1.14*10-10 fail on random Max error in 5th significant digit, because you can t get out of range for many iterations CS/ECE 552 Lecture Notes: Chapter 4 25 CS/ECE 552 Lecture Notes: Chapter 4 26 Pentium Bug Booth 2-bit Encoding Analysis There are are actually much worse errors in Pentium Errata book (and other microprocessors) These can cause completely incorrect results People believe hardware is always perfect (for software you pay for their bugs!!) Pentium bug caught public attention and Intel handled poorly curr bits bit to right info Op 00 0 mid of 0 s 0 00 1 end of 1 s +1 01 0 single 1 +1 01 1 end of 1 s +2 10 0 beg of 1 s -2 10 1 single 0-1 11 0 beg of 1 s -1 11 1 mid of 1 s 0 CS/ECE 552 Lecture Notes: Chapter 4 27 CS/ECE 552 Lecture Notes: Chapter 4 28

Non-restoring Division Final step may need correction if remainder and dividend opp signs, correction needed dividend, divisor same sign, remainder += D, quotient -=ulp dividend, divisor opp sign, emainder -= D, quotient +=ulp convert wierd quotient to 2 sc : 1 is 1, 1 is 0 shift left by one bit complement MSB shift 1 into LSB Floating-Point Numbers want to represent real numbers But uncountably infinite Recall scientific notation 3.15576 *10 9 (#seconds in a century!) 3,155,760,000 exponent says where the decimal point float Recall normalization use 3.14*10 10 NOT 0.314*10 11 or 31.4*10 9 MSD is [1,9] except for 0.0 CS/ECE 552 Lecture Notes: Chapter 4 29 CS/ECE 552 Lecture Notes: Chapter 4 30 Floating-Point Numbers Floating-Point Numbers computer floating-point is similar except binary number is -1 s * f * 2 e (note base is not stored) IEEE 754 uses base 2 reduce relative error (wobble) most significant bit is always 1, so don t store it For IEEE FP, store s, e,f as S, E, F S E F range n bias usually s = S e = E - bias f = 1+ F/2 n e.g., -1 s * (1.F) * 2 (E-1023) 1 8 23 single-precision 2*10 +/-38 23 127 1 11 52 double-precision 2*10 +/-308 52 1023 CS/ECE 552 Lecture Notes: Chapter 4 31 CS/ECE 552 Lecture Notes: Chapter 4 32

Floating-Point Numbers Exceptions S E F number 0 0 0 0 0 max 0 +inf 1 max 0 -inf x max!=0 NaN x 0!=0 denorm f = 0 + F/2 n see book for table Floating-Point Addition Like scientific notation 9.997 * 10 2 + 4.631 * 10-1 First step: align decimal points, second step: add 9.997 * 10 2 + 0.004631 * 10 2 10.001631 * 10 2 CS/ECE 552 Lecture Notes: Chapter 4 33 CS/ECE 552 Lecture Notes: Chapter 4 34 Floating-Point Addition Floating-Point Subtraction Third step: normalize the result often already normalized otherwise move only one digit Subtraction similar when adding different signs subtracting same signs 1.0001631 * 10 3 Example presumes infinite precision; with FP must round Figure CS/ECE 552 Lecture Notes: Chapter 4 35 CS/ECE 552 Lecture Notes: Chapter 4 36

Floating-Point Multiplication Example: 3.0 * 10 1 5.0 * 10 2 algorithm: multiple mantissas, add exponents check exponent in bounds --> exception normalize (and round) set sign Floating-Point Multiplication Hardware: Figure Exponent: e+ = e1 + e2 E+ = e+ + 1023 = E1-1023 + E2-1023 + 1023 E+ = E1 + E2-1023 -1023 = -(1111111111) = 0000000000 + 1 = +1 With 2 sc E+ = E1 + E2 + carryin! CS/ECE 552 Lecture Notes: Chapter 4 37 CS/ECE 552 Lecture Notes: Chapter 4 38 Floating-Point Multiplication Floating-Point Division Significand 23 or 52 bit non-negative integer multiplier E/ = E1 - E2 + 1023 = E1 - (E2-1) = E - (1 sc(e2)) For significand, use integer SRT with radix 4 or 16 (la Pentium) carry save adders in a wallace tree a shifter to normalize CS/ECE 552 Lecture Notes: Chapter 4 39 CS/ECE 552 Lecture Notes: Chapter 4 40

6-9 up 5 to even to make unbiased 1-4 down 0 unchanged xxxx.1... 1.. up xxxxx.10000 to even xxx.0.... 1... down xxx.0000000000 unchanged Rounding Rounding Need infinite bits? No - hold least significant bits guard bits - used for normalization - one bit right of LSB round bit - main round bit - one bit right of guard bit sticky - logical OR of all less significant bits round sticky 1 1 round up 1 0 round even 0 1 round down 0 0 no round CS/ECE 552 Lecture Notes: Chapter 4 41 CS/ECE 552 Lecture Notes: Chapter 4 42 Rounding IEEE FP bounds error to 1/2 units of the last place ULP Keeping error small and unbiased is important can accumulate after billions of operations other rounding modes Mixing small and large numbers in FP (3.1415... + 6 *10 22 ) - 6 *10 22!= 3.1415.. + (6 *10 22-6 *10 22 ) CS/ECE 552 Lecture Notes: Chapter 4 43