Arithmetic Processing

Similar documents
EE 109 Unit 6 Binary Arithmetic

COMPUTER ARITHMETIC (Part 1)

Number System. Introduction. Decimal Numbers

Chapter 3: part 3 Binary Subtraction

World Inside a Computer is Binary

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

DIGITAL ARITHMETIC. Miloš D. Ercegovac Computer Science Department University of California Los Angeles and

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Number representations

Number Systems and Computer Arithmetic

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

Organisasi Sistem Komputer

Advanced Computer Architecture-CS501

CS/COE 0447 Example Problems for Exam 2 Spring 2011

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

COMP 303 Computer Architecture Lecture 6

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

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

Module 2: Computer Arithmetic

Numbering systems. Dr Abu Arqoub

Number Systems and Conversions UNIT 1 NUMBER SYSTEMS & CONVERSIONS. Number Systems (2/2) Number Systems (1/2) Iris Hui-Ru Jiang Spring 2010

CHW 261: Logic Design

Chapter 4 Arithmetic Functions

Chapter 2. Data Representation in Computer Systems

ECE331: Hardware Organization and Design

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

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Digital Systems and Binary Numbers

CS 64 Week 1 Lecture 1. Kyle Dewey

Topic Notes: Bits and Bytes and Numbers

Arithmetic and Bitwise Operations on Binary Data

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

COMP Overview of Tutorial #2

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Topic Notes: Bits and Bytes and Numbers

COMP2611: Computer Organization. Data Representation

Number Systems CHAPTER Positional Number Systems

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

Timing for Ripple Carry Adder

MC1601 Computer Organization

CHAPTER 2 Data Representation in Computer Systems

CHAPTER 2 Data Representation in Computer Systems

Lecture 8: Addition, Multiplication & Division

Inf2C - Computer Systems Lecture 2 Data Representation

BINARY SYSTEM. Binary system is used in digital systems because it is:

Computer Arithmetic Ch 8

Computer Arithmetic Ch 8

CS & IT Conversions. Magnitude 10,000 1,

Representation of Numbers

Divide: Paper & Pencil

Chapter 5 : Computer Arithmetic

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

CMPE223/CMSE222 Digital Logic Design. Positional representation

Learning the Binary System

carry in carry 1101 carry carry

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

Integers. N = sum (b i * 2 i ) where b i = 0 or 1. This is called unsigned binary representation. i = 31. i = 0

COE 202: Digital Logic Design Number Systems Part 2. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

Binary Adders. Ripple-Carry Adder

Operators. Lecture 3 COP 3014 Spring January 16, 2018

Chapter 3 Data Representation

EE 486 Winter The role of arithmetic. EE 486 : lecture 1, the integers. SIA Roadmap - 2. SIA Roadmap - 1

Chapter 2: Number Systems

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

CO212 Lecture 10: Arithmetic & Logical Unit

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

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

CPS 104 Computer Organization and Programming

Lecture 2: Number Systems

CS 31: Introduction to Computer Systems. 03: Binary Arithmetic January 29

Chapter 2 Bits, Data Types, and Operations

Chapter 2 Bits, Data Types, and Operations

Binary Representations and Arithmetic

Chapter 10 - Computer Arithmetic

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

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

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

Chapter 10 Binary Arithmetics

9 Multiplication and Division

CSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators

Chapter 5: Computer Arithmetic. In this chapter you will learn about:

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

(+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)

Chapter 2 Bits, Data Types, and Operations

Internal Data Representation

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. Number Systems and Number Representation

Chapter 1 Review of Number Systems

Digital Fundamentals

Positional Number System

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

Adding Binary Integers. Part 4. Negative Binary. Integers. Adding Base 10 Numbers. Adding Binary Example = 10. Arithmetic Logic Unit

Number Systems and Their Representations

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

9/23/15. Agenda. Goals of this Lecture. For Your Amusement. Number Systems and Number Representation. The Binary Number System

Learning Objectives. Binary over Decimal. In this chapter you will learn about:

By, Ajinkya Karande Adarsh Yoga

Number Systems and Number Representation

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

Transcription:

CS/EE 5830/6830 VLSI ARCHITECTURE Chapter 1 Basic Number Representations and Arithmetic Algorithms Arithmetic Processing AP = (operands, operation, results, conditions, singularities) Operands are: Set of numerical values Range Precision (number of bits) Number Representation System (NRS) Operand: +, -, *, \, etc. Conditions: Values of results (zero, neg, etc.) Singularities: Illegal results (overflow, NAN, etc.) 1

Number Representation Need to map numbers to bits (or some other representation, but we ll use bits) Representation you choose matters! Complexity of arithmetic operations depends heavily on representation! But, be careful of conversions Arithmetic that s easy in one representation may lose its advantage when you convert back and forth Basic Fixed Point NRS Number represented by ordered n-tuple of symbols Symbols are digits n-tuple is a digit-vector Number of digits in digit-vector is precision 2

Digit Values A set of numerical values for the digits is the set of possible values for is the cardinality of Binary (cardinality 2) is Decimal (cardinality 10) is Balanced ternary (cardinality 3) is { 0,1,2,3,4,5,6,7,8,9 } Set of integers represented by a digit-vector with n digits is a finite set with max elements of Rule of Interpretation Mapping of set of digit-vectors to numbers (1,3) Thirteen Digit-Vectors Numbers (N, Z, R, ) 3

Mappings Digit-vectors N,R,Z, Nonredundant Digit-vectors Redundant N,R,Z, Not Useful! Digit-vectors N,R,Z, Ambiguous Positional Weighted Systems Integer x represented by digit vector Rule of interpretation Where weight vector is 4

Radix Number Systems Weights are not arbitrary they are related to a radix vector So that Or Fixed-Radix Systems In fixed-radix system all elements of the radix vector have the same value r (the radix) Weight vector is So Radix 2: Radix 4: Radix 10: 5

Mixed-Radix Systems Time is the most common Hours, Minutes, Seconds X=(5,37,43) = 20,263 seconds 5 x 3600 = 18,000 37 x 60 = 2,220 43 x 1 = 43 Total = 20,263 seconds Canonical Systems Canonical if Binary = {0,1} Octal = {0,1,2,3,4,5,6,7) Decimal = {0,1,2,3,4,5,6,7,8,9} Range of values with n radix-r digits is 6

Non-Canonical Systems Digit set that is non canonical Non-canonical decimal Non-canonical binary Redundant if non-canonical I.e. binary system with (1,1,0,1) and (1,1,1,-1) both represent thirteen Conventional Number Systems A system with fixed positive radix r and canonical set of digit values Radix-r conventional number system After all this fuss, these are what we ll mostly worry about Specifically binary (radix 2) We ll also see some signed-digit redundant binary (carry-save, signed-digit) 7

Aside Residue Numbers Example of a non-radix number system Weights are not defined recursively Residue Number System (RNS) uses a set of pairwise relatively prime numbers A positive integer x is represented by a vector Can allow fast add and multiply No notion of digits on left being more significant than digits on the right (i.e. no weighting) Aside Residue Numbers P = (17, 13, 11, 7, 5, 3, 2) Digit-vector (13 4 8 2 0 0 0) Number = thirty 30 mod 17 = 13 30 mod 13 = 4 30 mod 11 = 8 Etc 8

Lots of Choices Back to Binary Non-negative integers digits = {0,1} Range with n bits is Higher power of 2 radix group bits in to groups with bits X = (1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1) = ((1,1), (0,0), (0,1), (0,1), (1,1), (0,1)) = ( 3, 0, 1, 1, 3, 1) base 4 (quaternary) = ((1,1,0), (0,0,1), (0,1,1), (1,0,1)) = (6,1,3,5) base 8 (octal) = ((1,1,0,0)(0,1,0,1)(1,1,0,1)) = (C, 5, D) base 16 (hexadecimal) 9

Signed Integers Three choices for representing signed ints Directly in the number system Signed digit NRS, i.e. {-1, 0, 1} Use extra symbol to represent the sign Sign and Magnitude Additional mapping on positive integers True and Complement system Signed integer X Positive Integer X R Digit-Vector X Transformation Transform signed numbers into unsigned, then use conventional systems minus two x six x R (1,1,0) Z (signed) N (unsigned) Digit vectors 10

True and Complement System Signed integers in the range Negative represented by x R Such that C is the Complementation constant Unambiguous if Mapping is True forms Complement forms Converse Mapping Convert back and forth 11

Boundary conditions If x R = C /2 can be represented, you can assign it to either Representation is no longer symmetric Not closed under sign change operation If can be represented, then there are two representations of 0 Two standard forms Range complement system Also called Radix Complement Two s complement in radix 2 Digit Complement System Also called Diminished Radix Complement One s complement in radix 2 12

Two s Compliment For n bits in the digit vector, Example three bits: C = 8 is outside the range With 3 bits, you can t represent 8 So, only one representation of 0 can be represented, so you have a choice Usually choose second for sign detection Range is then (asymmetric) One s Compliment For n bits in the digit vector Example three bits: C = 7 is representable in 3 bits Two representations of 0 cannot be represented Symmetric range Range is then 13

Examples (n=3 bits) Two s compliment -3 represented as 101 111 represents -1 One s compliment -3 represented as 100 Range Comparison (3 bits) Decimal Binary (unsigned) 7 111 6 110 5 101 4 100 Sign & Magnitude Two s compliment One s Compliment 3 011 011 011 011 2 010 010 010 010 1 001 001 001 001 0 000 000/100 000 000/111-1 101 111 110-2 110 110 101-3 111 101 100-4 100 14

Example: 2 s comp, n=4-1 -2 1111 1110-3 1101-4 1100 +0 0000 +1 0001 0010 +2 0011 +3-5 1011-6 1010-7 1001-8 1000 0100 0101 0110 +6 0111 +7 +4 +5 Example: 1 s comp, n=4-0 -1 1111 1110-2 1101-3 1100-4 1011-5 1010 1001-6 1000-7 +0 0000 +1 0001 0010 +2 0011 +3 0100 +4 0101 +5 0110 +6 0111 +7 15

Converse Mapping (2 s comp) If If n 2 x = X n 1 2 n 1 + X i 2 i i=0 Most significant bit has negative weight, remaining have positive Two s Comp. Example n 2 x = X n 1 2 n 1 + X i 2 i i=0 Most significant bit has negative weight, remaining have positive n=5: X = 11011 = -16 + 8 + 0 + 2 + 1 = -5 X = 01011 = 0 + 8 + 0 + 2 + 1 = 11 16

Converse Mapping (1 s comp) Similar in one s complement (case for X n-1 =1) x = X n 1 (2 n 1 1) + n 2 i=0 X i 2 i Remember this! We ll use it later when we need to adjust things in arrays of signed addition. Think of partial product arrays in multiplication. One s Comp. Example x = X n 1 (2 n 1 1) + n 2 i=0 X i 2 i Most significant bit has negative weight, remaining have positive. Weight of MSB is different because C=2 n -1. Intuition is that You have to add 1 to jump over The extra representation of 0. n=5: X = 11011 = -(16-1) + 8 + 0 + 2 + 1 = -4 X = 01011 = 0 + 8 + 0 + 2 + 1 = 11 17

Sign Bits Conveniently, sign is determined by high-order bit Because (Assuming x R = C/2 is assigned to represent x = -C/2) Addition (unsigned) Adding two n-bit operands results in n+1 result bits Usually call the n+1 bit Cout In terms of digit vectors C out = overflow! 18

Addition (Signed) Assume no overflow for a moment Use the property Addition: two s comp. C=2 n, and mod2 n means ignore X n (the carry out)! Makes addition simple add the numbers and ignore the carry out x R y R c out + c in z R 19

Addition: one s comp. C=r n -1, so mod operation is not as easy z R =w R mod(2 n -1) So: Ignore c out Addition: one s comp. If the c out is 1, subtract 2 n (ignore c out ), and add 1 (end-around carry) x R y R c out + c in z R 20

Change of Sign Start with bitwise negation Flip every bit in the digit vector Boolean style: Fundamental property of n-digit radix-r + + Change of Sign One s Complement: { A = C A = r n 1 A = A if A 0 Two s Complement: { A = C A = r n A = A +1 if A 0 21

Another two s comp. check Verify the property Use two s complement definition Two s comp subtract y R x R + c out 1 c in z R 22

Two s comp add/subtract y R x R Sub c out + c in z R Two s comp add/subtract x R y R Sub Overflow? c out + z R c in a b c 00 0 01 1 10 1 11 0 23

Overflow (unsigned) Overflow condition means that the result can t be represented in n bits For unsigned addition, this simply means that the cout was 1 For n=4, this means the result was bigger than 15 1010 2 (10 10 ) + 1100 2 (12 10 ) = 10110 2 (22 10 ) Overflow (signed) Still the same definition the result can t be represented in n bits But, now not as easy as looking at cout For 4 bits, and two s comp, answer was smaller than 8 or larger than 7 Overflow if (pos) + (pos) = (neg) 5+6=11 or (neg) + neg) = (pos) -5+-6=-11 Can you ever have overflow with (pos) + (neg)? 24

Example: 2 s comp, n=4-1 -2 1111 1110-3 1101-4 1100 +0 0000 +1 0001 0010 +2 0011 +3-5 1011-6 1010-7 1001-8 1000 0100 0101 0110 +6 0111 +7 +4 +5 Overflow (signed) Overflow only possible if args are same sign Overflow if result is different sign 25

Overflow (signed) Or, consider all possible cases around MSB Xn-1 Yn-1 Cn-1 Cn Zn-1 OVF 0 0 0 0 0 No 0 0 1 0 1 Yes 0 1 0 0 1 No 0 1 1 1 0 No 1 0 0 0 1 No 1 0 1 1 0 No 1 1 0 1 0 Yes 1 1 1 1 1 No Implied Digits (unsigned) Unsigned numbers have an infinite number of leading 0 s 5,243 = 0,000,000,000,005,234 1 1010 = 0 0000 0000 0001 1010 Changing from n bits to m bits (m>n) is a simple matter of padding with 0 s to the left 26

Changing number of bits (signed) Signed numbers can be thought of as having infinite replicas of the sign bit to the left Four bits: Eight bits: Shifting Shifting corresponds to multiply and divide by powers of 2 Left arithmetic shift Shift in 0 s in LSB, OVF if Right arithmetic shift Divide by 2 (integer result)(1-bit shift) Remember to copy the sign bit in empty MSB! 27

Multiplication (unsigned) Pencil and paper method Compute n terms of and then sum them The ith term requires an i-position shift, and a multiplication of x by the single digit Y i Requires n-1 adders Multiplication (unsigned) 28

Multiplication (unsigned) Multiplication (unsigned) B 0 B 1 B 2 B 3 29

Multiplication (unsigned) Instead of using n-1 adders, can iterate with 1 takes n steps for n bits Serial Multiplicaton (unsigned) 30

Multiplication (signed!) Remember that MSB has negative weight Add partial products as normal Subtract multiplicand in last step Division (unsigned) x=qd+w (quotient, divisor, remainder) Consider 0<d, x<r n d (precludes /0 and OVF) Basic division is n iterations of the recurrence w[0] = x w[ j +1] = rw[ j] d q n 1 j j = 0,...,n 1 n 1 where q = q i r i and d = dr n i=0 i.e. divisor is aligned with most-significant half of residual 31

Division (unsigned) In each step of the iteration Get one digit of quotient Value of digit is bounded such that This means you find the right digit such that the current remainder is less than (shifted) divisor In binary you only have to guess 1 or 0 Guess 1 and fix if you re wrong (restoring) Long Division 32

Restoring Division 1. Shift current result one bit left 2. Subtract divisor from this result 3. If the result of step 2 is neg, q=0, else q=1 4. If the result of step 2 is neg, restore old value of result by adding divisor back 5. Repeat n times This is what the recurrence in the book says Restoring Division 33

Restoring Division Shift Subtract divisor (add negative) use tentative partial residual to decide on quotient bit partial residual was negative, so restore by adding divisor back in real partial residual is starting point for next iteration Shift Subtract divisor (add negative) use tentative partial residual to decide on quotient bit partial residual was positive, so residual is correct no restoration needed Shift Subtract divisor (add negative) use tentative partial residual to decide on quotient bit partial residual was negative, so restore by adding divisor back in real partial residual is starting point for next iteration Shift Subtract divisor (add negative) use tentative partial residual to decide on quotient bit partial residual was positive, so residual is correct no restoration needed Restoring Division Example 34

Non-performing Division Consider what happens Result at each step is 2r-d (r is current result) If the result is negative, we restore by adding d back in But, if you store the result in a separate place and don t update the result until you know if it s negative, then you can save some restoring steps Non-restoring Division Consider again At each step 2residual-d If it s negative, restore to 2r by adding d back in Then shift to get 4r, then subtract getting 4r-d Suppose you don t restore, but continued with the shift resulting in 4r-2d Now add d instead of subtract resulting in 4r-d That s what you wanted! 35

Non-restoring Division For positive partial residual subtract divisor For negative partial residual add divisor back in This corrects for the mistake you made on the last iteration If the last residual is negative do one final restoration Non-restoring Division Example 36

Whew! Basic number representation systems Unsigned, signed Conversions Basic addition, subtraction of signed numbers Multiplication of unsigned and signed Division of signed Now let s speed up the operations! 37