3-1 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Computer Architecture.

Slides:



Advertisements
Similar presentations
CENG536 Computer Engineering department Çankaya University.
Advertisements

Arithmetic Functions and Circuits
2-1 Chapter 2 - Data Representation Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Computer Architecture.
Chapter 2: Data Representation
Principles of Computer Architecture Miles Murdocca and Vincent Heuring Chapter 2: Data Representation.
Parallel Adder Recap To add two n-bit numbers together, n full-adders should be cascaded. Each full-adder represents a column in the long addition. The.
Henry Hexmoor1 Chapter 5 Arithmetic Functions Arithmetic functions –Operate on binary vectors –Use the same subfunction in each bit position Can design.
Assembly Language and Computer Architecture Using C++ and Java
Chapter 6 Arithmetic. Addition Carry in Carry out
Assembly Language and Computer Architecture Using C++ and Java
Chapter # 5: Arithmetic Circuits Contemporary Logic Design Randy H
2-1 Computer Organization Part Fixed Point Numbers Using only two digits of precision for signed base 10 numbers, the range (interval between lowest.
1 ECE369 Chapter 3. 2 ECE369 Multiplication More complicated than addition –Accomplished via shifting and addition More time and more area.
Copyright 2008 Koren ECE666/Koren Part.6a.1 Israel Koren Spring 2008 UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering Digital Computer.
Operations on data CHAPTER 4.
Dr. Bernard Chen Ph.D. University of Central Arkansas
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
Simple Data Type Representation and conversion of numbers
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
Data Representation – Binary Numbers
Computer Organization and Architecture Computer Arithmetic Chapter 9.
1 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
Computer Arithmetic Nizamettin AYDIN
Chapter 6-2 Multiplier Multiplier Next Lecture Divider
Binary Arithmetic Stephen Boyd March 14, Two's Complement Most significant bit represents sign. 0 = positive 1 = negative Positive numbers behave.
3-1 Chapter 3 - Arithmetic Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles of Computer Architecture.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 3.
Logical Circuit Design Week 8: Arithmetic Circuits Mentor Hamiti, MSc Office ,
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
Chapter 6: Computer Arithmetic and the ALU
IT253: Computer Organization
Computing Systems Basic arithmetic for computers.
Arithmetic Chapter 4.
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles of Computer.
Data Representation in Computer Systems
Chapter 4 – Arithmetic Functions and HDLs Logic and Computer Design Fundamentals.
Chapter # 5: Arithmetic Circuits
Chapter 6-1 ALU, Adder and Subtractor
5-1 Programmable and Steering Logic Chapter # 5: Arithmetic Circuits.
07/19/2005 Arithmetic / Logic Unit – ALU Design Presentation F CSE : Introduction to Computer Architecture Slides by Gojko Babić.
Number Systems. Why binary numbers? Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). Digital designer.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
L/O/G/O CPU Arithmetic Chapter 7 CS.216 Computer Architecture and Organization.
Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.
Floating Point Arithmetic
Operations on Bits Arithmetic Operations Logic Operations
Combinational Circuits
Computer Arithmetic See Stallings Chapter 9 Sep 10, 2009
Topics covered: Arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
CS/EE 3700 : Fundamentals of Digital System Design Chris J. Myers Lecture 5: Arithmetic Circuits Chapter 5 (minus 5.3.4)
Addition, Subtraction, Logic Operations and ALU Design
Number Representation and Arithmetic Circuits
Lecture #23: Arithmetic Circuits-1 Arithmetic Circuits (Part I) Randy H. Katz University of California, Berkeley Fall 2005.
ECE DIGITAL LOGIC LECTURE 15: COMBINATIONAL CIRCUITS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2015, 10/20/2015.
Chapter 8 Computer Arithmetic. 8.1 Unsigned Notation Non-negative notation  It treats every number as either zero or a positive value  Range: 0 to 2.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
Floating Point Representations
Chapter Contents 3.1 Overview 3.2 Fixed Point Addition and Subtraction
Integer Division.
Unit -2 ARITHMETIC.
King Fahd University of Petroleum and Minerals
Digital Logic & Design Lecture 02.
Overview Part 1 – Design Procedure Part 2 – Combinational Logic
ECE 352 Digital System Fundamentals
Chapter3 Fixed Point Representation
Presentation transcript:

3-1 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Computer Architecture and Organization Miles Murdocca and Vincent Heuring Chapter 3 – Arithmetic

3-2 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Chapter Contents 3.1 Fixed Point Addition and Subtraction 3.2 Fixed Point Multiplication and Division 3.3 Floating Point Arithmetic 3.4 High Performance Arithmetic

3-3 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Computer Arithmetic Using number representations from Chapter 2, we will explore four basic arithmetic operations: addition, subtraction, multiplication, and division. Significant issues include: fixed point vs. floating point arithmetic, overflow and underflow, handling of signed numbers, and performance. We look first at fixed point arithmetic, and then at floating point arithmetic.

3-4 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Binary Numbers can be Represented on a Number Circle Numbers are added or subtracted on the number circle by traversing clockwise for addition and counterclockwise for subtraction. Unlike the number line (a) where overflow never occurs, overflow occurs when a transition is made from +3 to -4 while proceeding around the number circle when adding, or from -4 to +3 while subtracting.

3-5 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Overflow Overflow occurs when the addition of two positive numbers produces a negative result, or when the addition of two negative numbers produces a positive result. Adding operands of unlike signs never produces an overflow. Notice that discarding the carry out of the most significant bit during two’s complement addition is a normal occurrence, and does not by itself indicate overflow. As an example of overflow, consider adding ( = 160) 10, which produces a result of in an 8-bit two’s complement format: = = = -96 (not 160 because the sign bit is 1.)

3-6 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Sign Extension The leftmost bit is assigned to the sign. What happens to the sign bit if we place a number into a larger or smaller word? For positive numbers, all that we need to do is pad the left side with 0s: For negative numbers, we cannot simply pad the left side with 0s because that would change the value of the number:

3-7 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Sign Extension (continued) As it turns out, all that we need to do is copy the sign bit for as many places as there are to the left and the number will be correctly extended, regardless of the value of the sign. This is known as sign extension:

3-8 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Sign Extension (continued) If we want to reduce the size of the word, we can simply remove bits on the left and the resulting sign will be correct, as long as the number can be represented in the remaining bits:

3-9 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Ripple Carry Adder Two binary numbers A and B are added from right to left, creating a sum and a carry at the outputs of each full adder for each bit position.

3-10 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Constructing Larger Adders A 16-bit adder can be made up of a cascade of four 4-bit ripple-carry adders.

3-11 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Full Subtractor Truth table and schematic symbol for a ripple-borrow subtractor:

3-12 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Ripple-Borrow Subtractor A ripple-borrow subtractor can be composed of a cascade of full subtractors. Two binary numbers A and B are subtracted from right to left, creating a difference and a borrow at the outputs of each full subtractor for each bit position.

3-13 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Combined Adder/Subtractor A single ripple-carry adder can perform both addition and subtraction, by forming the two’s complement negative for B when subtracting. (Note that +1 is added at c 0 for two’s complement.)

3-14 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring One’s Complement Addition An example of one’s complement integer addition with an end-around carry:

3-15 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Number Circle (Revisited) Number circle for a three-bit signed one’s complement representation. Notice the two representations for 0.

3-16 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring End-Around Carry for Fractions The end-around carry complicates one’s complement addition for non- integers, and is generally not used for this situation. The issue is that the distance between the two representations of 0 is 1.0, whereas the rightmost fraction position is less than 1.

3-17 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Multiplication Example Multiplication of two 4-bit unsigned binary integers produces an 8-bit result. Multiplication of two 4-bit signed binary integers produces only a 7-bit result (each operand reduces to a sign bit and a 3-bit magnitude for each operand, producing a sign-bit and a 6-bit result).

3-18 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring A Serial Multiplier

3-19 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Example of Multiplication Using Serial Multiplier

3-20 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Example of Base 2 Division (7 / 3 = 2) 10 with a remainder R of 1. Equivalently, (0111/ 11 = 10) 2 with a remainder R of 1.

3-21 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Serial Divider

3-22 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Division Example Using Serial Divider

3-23 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Multiplication of Signed Integers Sign extension to the target word size is needed for the negative operand(s). A target word size of 8 bits is used here for two 4-bit signed operands, but only a 7-bit target word size is needed for the result.

3-24 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Carry-Lookahead Addition s i = a i b i c i + a i b i c i + a i b i c i + a i b i c i c i+1 = b i c i + a i c i + a i b i c i+1 = a i b i + (a i + b i )c i c i+1 = G i + P i c i G i = a i b i and P i = a i + b i c 0 = 0 c 1 = G 0 c 2 = G 1 + P 1 G 0 c 3 = G 2 + P 2 G 1 + P 2 P 1 G 0 c 4 = G 3 + P 3 G 2 + P 3 P 2 G 1 + P 3 P 2 P 1 G 0 Carries are represented in terms of G i (generate) and P i (propagate) expressions.

3-25 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Carry Lookahead Adder Maximum gate delay for the carry generation is only 3. The full adders introduce two more gate delays. Worst case path is 5 gate delays.

3-26 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Floating Point Arithmetic Floating point arithmetic differs from integer arithmetic in that exponents must be handled as well as the magnitudes of the operands. The exponents of the operands must be made equal for addition and subtraction. The fractions are then added or subtracted as appropriate, and the result is normalized. Ex: Perform the floating point operation: (.101   2 4 ) 2 Start by adjusting the smaller exponent to be equal to the larger exponent, and adjust the fraction accordingly. Thus we have.101  2 3 =.010  2 4, losing.001  2 3 of precision in the process. The resulting sum is ( )  2 4 =  2 4 =.1001  2 5, and rounding to three significant digits,.100  2 5, and we have lost another  2 4 in the rounding process.

3-27 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Floating Point Arithmetic (Cont’) If we simply added the numbers using as much precision as we needed and then applied rounding only in the final normalization step, then the calculation would go like this: Normalizing yields × 2 5, and rounding to three significant digits using the round to nearest even method yields.101 × 2 5. Which calculation is correct.100 x 2 5 or.101 x 2 5 ? According to the IEEE 754 standard, the final result should be the same as if the maximum precision needed is used before applying the rounding method, and so the correct result is.101 × 2 5. So what do we do?

3-28 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Guard, Round, and Sticky Bits This raises the issue of how to compute the intermediate results with sufficient accuracy and without requiring too much hardware, and for this we use guard, round, and sticky bits. For the previous example, applying guard (g) and round (r) bits with the round toward nearest even method, we have: Only one extra bit is needed for this intermediate result, the guard bit (g), but we also show the round bit (r = 0) to locate its position. As we shift the number to normalize, we set a sticky bit (s) if any of the shifted out bits are nonzero. For this case, there are no nonzero bits to the right of the r bit and so s = 0: (see next slide)

3-29 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Guard, Round, and Sticky Bits (Cont’) Now for the rounding step: simply append the sticky bit to the right of the result before rounding. There is no tie as there would be for and so we round up, otherwise we would have rounded down to the closest even number (.100): For this case, the guard, round, and sticky bits changed our previous result. Note that if r is 0 instead of 1, so that the grs combination is 100, we would have rounded down to.100 because.100 is even whereas.101 is not.

3-30 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Floating Point Multiplication/Division Floating point multiplication/division are performed in a manner similar to floating point addition/subtraction, except that the sign, exponent, and fraction of the result can be computed separately. Like/unlike signs produce positive/negative results, respectively. Exponent of result is obtained by adding exponents for multiplication, or by subtracting exponents for division. Fractions are multiplied or divided according to the operation, and then normalized. Ex: Perform the floating point operation: (+.110  2 5 ) / (+.100  2 4 ) 2 The source operand signs are the same, which means that the result will have a positive sign. We subtract exponents for division, and so the exponent of the result is 5 – 4 = 1. We divide fractions, producing the result: 110/100 = Putting it all together, the result of dividing (+.110  2 5 ) by (+.100  2 4 ) produces (+1.10  2 1 ). After normalization, the final result is (+.110  2 2 ).

3-31 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring The Booth Algorithm Booth multiplication reduces the number of additions for intermediate results, but can sometimes make it worse as we will see. Positive and negative numbers treated alike.

3-32 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring A Worst Case Booth Example A worst case situation in which the simple Booth algorithm requires twice as many additions as serial multiplication.

3-33 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Bit-Pair Recoding (Modified Booth Algorithm)

3-34 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Coding of Bit Pairs

3-35 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Parallel Pipelined Array Multiplier

3-36 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Newton’s Iteration for Zero Finding The goal is to find where the function f(x) crosses the x axis by starting with a guess x i and then using the error between f(x i ) and zero to refine the guess. A three-bit lookup table for computing x 0 : The division operation a/b is computed as a  1/b. Newton’s iteration provides a fast method of computing 1/b.

3-37 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Residue Arithmetic Implements carryless arithmetic (thus fast!), but comparisons are difficult without converting to a weighted position code. Representation of the first twenty decimal integers in the residue number system for the given moduli:

3-38 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Examples of Addition and Multiplication in the Residue Number System

3-39 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring 16-bit Group Carry Lookahead Adder A16-bit GCLA is composed of four 4-bit CLAs, with additional logic that generates the carries between the four-bit groups. GG 0 = G 3 + P 3 G 2 + P 3 P 2 G 1 + P 3 P 2 P 1 G 0 GP 0 = P 3 P 2 P 1 P 0 c 4 = GG 0 + GP 0 c 0 c 8 = GG 1 + GP 1 c 4 = GG 1 + GP 1 GG 0 + GP 1 GP 0 c 0 c 12 = GG 2 + GP 2 c 8 = GG 2 + GP 2 GG 1 + GP 2 GP 1 GG 0 + GP 2 GP 1 GP 0 c 0 c 16 = GG 3 + GP 3 c 12 = GG 3 + GP 3 GG 2 + GP 3 GP 2 GG 1 + GP 3 GP 2 GP 1 GG 0 + GP 3 GP 2 GP 1 GP 0 c 0

3-40 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring 16-Bit Group Carry Lookahead Adder Each CLA has a longest path of 5 gate delays. In the GCLL section, GG and GP signals are generated in 3 gate delays; carry signals are generated in 2 more gate delays, resulting in 5 gate delays to generate the carry out of each GCLA group and 10 gates delays on the worst case path (which is s 15 – not c 16 ).