Arithmetic Processing. Basic Fixed Point NRS. Number Representation. Digit Values. Rule of Interpretation CS/EE 5830/6830 VLSI ARCHITECTURE

Similar documents
Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Computer Science 281 Binary and Hexadecimal Review

Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

Lecture 2. Binary and Hexadecimal Numbers

Useful Number Systems

The string of digits in the binary number system represents the quantity

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

Lecture 8: Binary Multiplication & Division

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

CSI 333 Lecture 1 Number Systems

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

Solution for Homework 2

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

CS201: Architecture and Assembly Language

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

CPEN Digital Logic Design Binary Systems

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

Chapter 1: Digital Systems and Binary Numbers

NUMBER SYSTEMS. 1.1 Introduction

NUMBER SYSTEMS. William Stallings

Lecture 11: Number Systems

Number Representation

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

Systems I: Computer Organization and Architecture

COMPSCI 210. Binary Fractions. Agenda & Reading

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

3. Convert a number from one number system to another

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

RN-Codings: New Insights and Some Applications

Binary Numbers. Binary Octal Hexadecimal

Number Systems and Radix Conversion

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

AN617. Fixed Point Routines FIXED POINT ARITHMETIC INTRODUCTION. Thi d t t d ith F M k Design Consultant

Positional Numbering System

Recall the process used for adding decimal numbers. 1. Place the numbers to be added in vertical format, aligning the decimal points.

RN-coding of Numbers: New Insights and Some Applications

2011, The McGraw-Hill Companies, Inc. Chapter 3

Digital Design. Assoc. Prof. Dr. Berna Örs Yalçın

Number Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi)

Implementation of Modified Booth Algorithm (Radix 4) and its Comparison with Booth Algorithm (Radix-2)

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

An Efficient RNS to Binary Converter Using the Moduli Set {2n + 1, 2n, 2n 1}

DNA Data and Program Representation. Alexandre David

2 Number Systems. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

Comp 255Q - 1M: Computer Organization Lab #3 - Machine Language Programs for the PDP-8

Number and codes in digital systems

Paramedic Program Pre-Admission Mathematics Test Study Guide

Numbering Systems. InThisAppendix...

Informatica e Sistemi in Tempo Reale

CYCLIC REDUNDANCY CHECKS IN USB. Introduction. Two-minute mathematical background

Binary Numbering Systems

Decimals Adding and Subtracting

Chapter 2. Binary Values and Number Systems

The finite field with 2 elements The simplest finite field is

BINARY CODED DECIMAL: B.C.D.

Base Conversion written by Cathy Saxton

Binary Adders: Half Adders and Full Adders

Binary Representation

8 Primes and Modular Arithmetic

YOU MUST BE ABLE TO DO THE FOLLOWING PROBLEMS WITHOUT A CALCULATOR!

Unsigned Conversions from Decimal or to Decimal and other Number Systems

Subnetting Examples. There are three types of subnetting examples I will show in this document:

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University

PREPARATION FOR MATH TESTING at CityLab Academy

Arithmetic in MIPS. Objectives. Instruction. Integer arithmetic. After completing this lab you will:

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

1 Description of The Simpletron

U.C. Berkeley CS276: Cryptography Handout 0.1 Luca Trevisan January, Notes on Algebra

The mathematics of RAID-6

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

Verilog - Representation of Number Literals

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

Math Workshop October 2010 Fractions and Repeating Decimals

Lecture 13 - Basic Number Theory.

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Everything you wanted to know about using Hexadecimal and Octal Numbers in Visual Basic 6

CHAPTER 5 Round-off errors

Cryptography and Network Security. Prof. D. Mukhopadhyay. Department of Computer Science and Engineering. Indian Institute of Technology, Kharagpur

Object Oriented Software Design

Continued Fractions and the Euclidean Algorithm

MACHINE INSTRUCTIONS AND PROGRAMS

Accuplacer Arithmetic Study Guide

Object Oriented Software Design

=

CHAPTER 5. Number Theory. 1. Integers and Division. Discussion

Sistemas Digitais I LESI - 2º ano

Z80 Instruction Set. Z80 Assembly Language

Quotient Rings and Field Extensions

Cyber Security Workshop Encryption Reference Manual

Chapter Binary, Octal, Decimal, and Hexadecimal Calculations

Binary, Hexadecimal, Octal, and BCD Numbers

Pre-Algebra Lecture 6

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.) 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 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 { 0,1,2,3,4,5,6,7,8,9 } Balanced ternary (cardinality 3) is 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, ) 1

Mappings Positional Weighted Systems Integer x represented by digit vector Digit-vectors N,R,Z, Not Useful! Rule of interpretation Nonredundant Where weight vector is Digit-vectors N,R,Z, Redundant Digit-vectors N,R,Z, Ambiguous Radix Number Systems Fixed-Radix Systems Weights are not arbitrary they are related to a radix vector In fixed-radix system all elements of the radix vector have the same value r (the radix) Weight vector is So that So Or Radix 2: Radix 4: Radix 10: Mixed-Radix Systems Canonical 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 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 2

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) 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 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) 3

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 True and Complement System Signed integers in the range Converse Mapping Convert back and forth Negative represented by x R Such that C is the Complementation constant Unambiguous if Mapping is True forms Complement forms Boundary conditions If x R = C /2 it to either can be represented, you can assign 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 4

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

Converse Mapping (2 s comp) Two s Comp. Example 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 If n=5: X = 11011 = -16 8 0 2 1 = -5 X = 01011 = 0 8 0 2 1 = 11 n 2 x = X n 1 2 n 1 X i 2 i i=0 Most significant bit has negative weight, remaining have positive Converse Mapping (1 s comp) One s Comp. Example Similar in one s complement (case for X n-1 =1) x = X n 1 (2 n 1 1) n 2 X i 2 i i=0 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. 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 Sign Bits Conveniently, sign is determined by high-order bit Because Addition (unsigned) Adding two n-bit operands results in n1 result bits Usually call the n1 bit Cout (Assuming x R = C/2 is assigned to represent x = -C/2) In terms of digit vectors C out = overflow! 6

Addition (Signed) Addition: two s comp. Assume no overflow for a moment Use the property 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 Addition: one s comp. Addition: one s comp. C=r n -1, so mod operation is not as easy z R =w R mod(2 n -1) If the c out is 1, subtract 2 n (ignore c out ), and add 1 (end-around carry) x R y R So: Ignore c out c out z R c in Change of Sign Change of Sign Start with bitwise negation Flip every bit in the digit vector Boolean style: Fundamental property of n-digit radix-r 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 7

Another two s comp. check Two s comp subtract Verify the property Use two s complement definition y R x R c out 1 c in z R Two s comp add/subtract Two s comp add/subtract y R y R Sub cout x R c in Sub Overflow? cout x R c in a b c 00 0 01 1 10 1 11 0 z R z R Overflow (unsigned) Overflow (signed) 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 ) 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) 56=11 or (neg) neg) = (pos) -5-6=-11 Can you ever have overflow with (pos) (neg)? 8

Example: 2 s comp, n=4 Overflow (signed) -1-2 1111 1110-3 1101-4 1100-5 1011-6 1010-7 1001 1000-8 0 0000 1 0001 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 Overflow only possible if args are same sign Overflow if result is different sign Overflow (signed) Implied Digits (unsigned) 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 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 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! 9

Multiplication (unsigned) 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) Multiplication (unsigned) B 0 B 1 B 2 B 3 Multiplication (unsigned) Serial Multiplicaton (unsigned) Instead of using n-1 adders, can iterate with 1 takes n steps for n bits 10

Multiplication (signed!) Division (unsigned) Remember that MSB has negative weight Add partial products as normal Subtract multiplicand in last step x=qdw (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 Division (unsigned) Long Division 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) Restoring Division 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 11

Restoring Division Restoring Division Example 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 Non-performing Division Non-restoring 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 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! Non-restoring Division Non-restoring Division Example 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 12

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! 13