CSE 246: Computer Arithmetic Algorithms and Hardware Design Instructor: Prof. Chung-Kuan Cheng Winter 2004 Lecture 2.

Slides:



Advertisements
Similar presentations
ECE 331 – Digital System Design
Advertisements

Radix Conversion Given a value X represented in source system with radix  s, represent the same number in a destination system with radix  d Consider.
CENG536 Computer Engineering Department Çankaya University.
C. Walter, Data Integrity for Modular Arithmetic, CHES 2000 CHES 2000 Data Integrity in Hardware for Modular Arithmetic Colin Walter Computation Department,
CSE 246: Computer Arithmetic Algorithms and Hardware Design Instructor: Prof. Chung-Kuan Cheng Lecture 6.
UNIVERSITY OF MASSACHUSETTS Dept
Congruence class arithmetic. Definitions: a ≡ b mod m iff a mod m = b mod m. a  [b] iff a ≡ b mod m.
MOHD. YAMANI IDRIS/ NOORZAILY MOHAMED NOOR 1 Lecture 3 Number System.
Level ISA3: Information Representation
Assembly Language and Computer Architecture Using C++ and Java
CSE 246: Computer Arithmetic Algorithms and Hardware Design Instructor: Prof. Chung-Kuan Cheng Fall 2006 Lecture 11 Cordic, Log, Square, Exponential Functions.
Computer Arithmetic, Multiplexers Prof. Sin-Min Lee Department of Computer Science.
CSE 246: Computer Arithmetic Algorithms and Hardware Design
CSE-221 Digital Logic Design (DLD)
CSE 246: Computer Arithmetic Algorithms and Hardware Design Instructor: Prof. Chung-Kuan Cheng Winter 2004 Lecture 1.
Improving Power And Performance of Embedded Applications Using Residue Number System Compilers For Embedded Systems Rooju Chokshi.
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
Chapter Chapter Goals Know the different types of numbers Describe positional notation.
ECE 301 – Digital Electronics Course Introduction, Number Systems, Conversion between Bases, and Basic Binary Arithmetic (Lecture #1)
ECE 331 – Digital System Design
CSE 246: Computer Arithmetic Algorithms and Hardware Design Instructor: Prof. Chung-Kuan Cheng Winter 2004 Lecture 8.
CSE 246: Computer Arithmetic Algorithms and Hardware Design Instructor: Prof. Chung-Kuan Cheng Winter 2004 Lecture 7.
CSE 246: Computer Arithmetic Algorithms and Hardware Design Numbers: RNS, DBNS, Montgomory Prof Chung-Kuan Cheng Lecture 3.
CSE20 Lecture 3 Number Systems: Negative Numbers 1.Sign and Magnitude Representation 2.1’s Complement Representation 3.2’s Complement Representation 1.
Fixed-Point Negative Numbers Two Common Forms: 1.Signed-Magnitude Form 2.Complement Forms Signed-Magnitude Numbers First Digit is Sign Digit, Remaining.
ECE 645 – Computer Arithmetic Lecture 10: Fast Dividers ECE 645—Computer Arithmetic 4/15/08.
Lecture 12: Computer Arithmetic Today’s topic –Numerical representations –Addition / Subtraction –Multiplication / Division 1.
Lecture for Week Spring.  Numbers can be represented in many ways. We are familiar with the decimal system since it is most widely used in everyday.
Positional Number Systems
Mathematics of Cryptography Part I: Modular Arithmetic
Number Systems - Part II
Coping With the Carry Problem 1. Limit Carry to Small Number of Bits Hybrid Redundant Residue Number Systems 2.Detect the End of Propagation Rather Than.
ECE 8053 Introduction to Computer Arithmetic (Website: Course & Text Content: Part 1: Number Representation.
General Fixed Radix Number Systems Nonredundant Positive radix, ß n digits in digit set Vector:
The Polynomial Time Algorithm for Testing Primality George T. Gilbert.
Part.7.1 Copyright 2007 Koren & Krishna, Morgan-Kaufman FAULT TOLERANT SYSTEMS Part 7 - Coding.
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
Great Theoretical Ideas in Computer Science.
07/19/2005 Arithmetic / Logic Unit – ALU Design Presentation F CSE : Introduction to Computer Architecture Slides by Gojko Babić.
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Reconfigurable Computing - Multipliers: Options in Circuit Design John Morris Chung-Ang University The University of Auckland ‘Iolanthe’ at 13 knots on.
Integer Conversion Between Decimal and Binary Bases Conversion of decimal to binary more complicated Task accomplished by –Repeated division of decimal.
Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.
Integer Representation for People Computer Organization and Assembly Language: Module 3.
New Mexico Computer Science for All Author: Ed Angel Title: Bits and Bytes.
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
ECE 8053 Introduction to Computer Arithmetic (Website: Course & Text Content: Part 1: Number Representation.
Mohammad Reza Najafi Main Ref: Computer Arithmetic Algorithms and Hardware Designs (Behrooz Parhami) Spring 2010 Class presentation for the course: “Custom.
Computer Organization and Design Information Encoding II Montek Singh Wed, Aug 29, 2012 Lecture 3.
Unconventional Fixed-Radix Number Systems
1 Lect # 2 Boolean Algebra and Logic Gates Boolean algebra defines rules for manipulating symbolic binary logic expressions. –a symbolic binary logic expression.
1 CS151 Introduction to Digital Design Chapter 1 Lecture 3.
Copyright 2008 Koren ECE666/Koren Part.7b.1 Israel Koren Spring 2008 UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering Digital Computer.
CSE 246: Computer Arithmetic Algorithms and Hardware Design Instructor: Prof. Chung-Kuan Cheng Fall 2006 Lecture 7 Division.
Reconfigurable Computing - Options in Circuit Design John Morris Chung-Ang University The University of Auckland ‘Iolanthe’ at 13 knots on Cockburn Sound,
Reconfigurable Computing - Options in Circuit Design John Morris Chung-Ang University The University of Auckland ‘Iolanthe’ at 13 knots on Cockburn Sound,
Choosing RNS Moduli Assume we wish to represent 100, Values Standard Binary  lg 2 (100,000) 10  =   =17 bits RNS(13|11|7|5|3|2), Dynamic.
Digital logic COMP214  Lecture 2 Dr. Sarah M.Eljack Chapter 1 1.
Dr. ClincyLecture 2 Slide 1 CS Chapter 2 (1 of 5) Dr. Clincy Professor of CS Note: Do not study chapter 2’s appendix (the topics will be covered.
UNIVERSITY OF MASSACHUSETTS Dept
UNIVERSITY OF MASSACHUSETTS Dept
COMPUTING FUNDAMENTALS
CSE 575 Computer Arithmetic Spring 2003 Mary Jane Irwin (www. cse. psu
Unconventional Fixed-Radix Number Systems
Data Representation in Computer Systems
UNIVERSITY OF MASSACHUSETTS Dept
ECE 301 – Digital Electronics
Presentation transcript:

CSE 246: Computer Arithmetic Algorithms and Hardware Design Instructor: Prof. Chung-Kuan Cheng Winter 2004 Lecture 2

CSE 2462 Topics:  Redundant Number Systems  Residue Number Systems Mixed Radix Number Systems (as they pertain to conversions of Residue Number Systems)

CSE 2463 Redundant Number Systems  Examine number systems that can be characterized by the 3-tuple (r, , ) r : radix, [, ] : set of digits  The redundancy of such a system is said to be non-redundant if  -  = r redundant if  -  > r  minimally redundant if  -  = r + 1  maximally redundant if  -  =2r - 1  over redundant if  -  > 2r - 1

CSE 2464 Redundant Number Systems  Ex: (2,0,2) Redundant - furthermore, minimally redundant Addition example: (6) (7) [3 not in radix] = 4*2 + 2*2 +1 = 13 =

CSE 2465 Redundant Number Systems  More addition examples:

CSE 2466 Redundant Number Systems  What has redundancy bought us? From the examples, it seems carry propagation has been somewhat reduced Intuitively - redundancy acts as a buffer against carry propagation However, carry propagation was not eliminated in (2,0,2) Need to formalize the degree to which a particular degree of redundancy eliminates carry propagation

CSE 2467 Redundant Number Systems  To formalize: x i+1 x i where x i + y i = r*t i+1 + w i + y i+1 y i t i+1 w i t i+2 w i+1 t i+1 + w i+1 we must bound t i+1 + w i+1 for all i to eliminate carry propagation

CSE 2468 Redundant Number Systems As x i and y i are in [, ] and x i + y i = r * t i+1 + w i+1 12  r*t i+1 + w i  2 suppose there exist and  such that 2  t i+1   we need 3 -  w i+1   -  to avoid propagation. Since this must be true for all i, whether the subscript is i or i+1 is not important. From 2 & 3 we have 4r* +  -  r*t i+1 + w i+1  r* +  -  From 1 & 4 we have 52  r* +  - 

CSE 2469 Redundant Number Systems 52  r* +  -  gives the following bounds for &  to insure no propagation   /(r-1)  /(r-1) For (2,0,2):   /(r-1) ->   2/(2-1)  /(r-1) ->  0/(2-1) which, from 3 means all w i must be in the range [0,0] and there exist inputs requiring carry propagation

CSE Redundant Number Systems  How then to ensure that no carry propagation is needed? Change (r, , ) Consider (3,0,5)   /(r-1) ->   5/(3-1)  /(r-1) ->  0/(3-1) yields  : 3 (first integer after 5/2) : 0 From 3, this gives a range on w i of [0,2] Thus, when presented with multiple possibilities for representing the sum of two digits, always choose terms in [0,2] and there will be no carry propagation

CSE Redundant Number Systems Ex: for (3,0,5) = 8 could use 15, but choose from [0,2] 22 yielding 22 and no propagation

CSE Redundant Number Systems  Advantages Constant time addition/subtraction!  Disadvantages More space Comparison  no unique forms/representations  conversion to canonical form as expensive as summation  Uses: excellent for intermediate results of addition  Multiplication  DSP loops that have no comparisons

CSE Residue Number Systems  Define a Residue Number System as follows For any given integer x, x=(x 1 |x 2 |...|x k )RNS(P 1 |P 2 |...|P k ) where x i = x mod P i and  i,j P i is relatively prime to P j EX: 84 = (0|4|0)RNS(7|5|3) 1 = (1|1|1)RNS(7|5|3) 2 = (2|2|2)RNS(7|5|3) 3 = (3|3|0)RNS(7|5|3) Residue numbers are not positional. Residue numbers have unique representations mod i.e. for (7|5|3) there are unique representations of

CSE Residue Number Systems  Need a conversion system to/from binary  What benefit to doing operations in RNS? Binary # RNS ops +,-,* Binary # RNS #

CSE Residue Number Systems  Addition (subtraction is similar) x+y = ((x 1 +y 1 ) p 1 | (x 2 +y 2 ) p 2 |... | (x k +y k ) p k )RNS(P 1 |P 2 |...|P k ) where x i = (x) p i and y i = (y) p i  Multiplication x*y = ((x 1 *y 1 ) p 1 | (x 2 *y 2 ) p 2 |... | (x k *y k ) p k )RNS(P 1 |P 2 |...|P k ) where x i = (x) p i and y i = (y) p i  Division ? Hard. What does a fraction look like in RNS?

CSE Residue Number Systems  Advantages: Parallel processing of +,*,- on smaller numbers Adding more primes without increasing range allows for use of fields to assist in fault tolerance (Ex: go from (7|5|3) to (7|5|3|2) where last field is used for parity)  Disadvantages: No division Comparison non-trivial Conversion costs  How to do conversion?

CSE Residue Number Systems  Conversion: RNS -> Binary # Given (x 1 |x 2 |...|x k )RNS(P 1 |P 2 |..|P k ) Binary number x = mod where  i = inv  One may consider, for the purposes of computation, all  i as being a pre-defined part of each particular RNS system See: Chinese Remainder Theorem

CSE Residue Number Systems  Conversion -> Bin# example: 84 = (0|4|0)RNS(7|5|3) For (7|5|3): ( 1 * 5*3/7) 7 = 1   1 : 1 ( 2 * 7*3/5) 5 = 1   2 : 1 ( 3 * 7*5/3) 3 = 1   3 : 2 x = (0* 1 *5*3*7/7 + 4* 2 *7*3*5/5 + 0* 3 *7*5*3/3) 105 x = (0 + 4* 2 *21 + 0) 105 x = (4*1*21) 105 =

CSE Residue Number Systems  Conversion -> Bin # example: 1 = (1|1|1)RNS(7|5|3) ( 1 * 5*3/7) 7 = 1   1 : 1 ( 2 * 7*3/5) 5 = 1   2 : 1 ( 3 * 7*5/3) 3 = 1   3 : 2 x = (1* 1 *5*3*7/7 + 1* 2 *7*3*5/5 + 1* 3 *7*5*3/3) 105 x = (1* 1 *15 + 1* 2 *21 + 1* 3 *35) 105 x = (1*1*15+1*1*21+1*2*35) 105 =(106) 105 = 1 105

CSE Residue Number Systems  Minimize: total length of primes (determining range) max length of any prime (determining HW cost/delay per unit) # of primes (determining # of parallel units)  Popular choices: 2 r -1 (2,3 particularly popular) Thm: 2 a -1 & 2 b -1 are relatively prime iff a & b are relatively prime Binary # RNS ops +,-,* Binary # RNS # Conversion -> Chinese remainder theorem How to choose primes? What about Bin -> RNS?

CSE Residue Number Systems  Binary # to RNS conversion Uses a lookup table Observation: for n digit binary number y (y n-1, y n-2,...,y 0 ) p i = [(2 n-1 ) p i *y n-1 + (2 n-2 ) p i *y n (2 0 ) p i *y 0 ] p i Use a table to store (2 i ) p i Example for (7|5|3) (1011)=(x 1 |x 2 |x 3 )RNS(7|5|3) x 1 = (1+2+1) 7 = 4 x 2 = (3+2+1) 5 = 1 x 3 = (2+2+1) 3 = 2

CSE Residue Number Systems  Comparison Could convert back and forth to/from binary. Another approach: convert to a mixed radix system, as numbers in a mixed radix system are comparable.

CSE Mixed Radix Number Systems  We shall describe a Mixed Radix System as follows: x =(Z k-1 |Z k-2 |...Z 0 )MRS(P k-1 |P k-2 |...|P 1 ) x = Z k-1 P k-1 P k-2...P 1 + Z k-2 P k-2 P k-1...P Z 1 P 1 +Z 0

CSE Mixed Radix Number Systems  Conversion from RNS to MRS Given x = (x k-1 |x k-2 |...|x 0 )RNS(P k-1 |P k-2 |...|P 0 ) We want x=(Z k-1 |Z k-2 |...|Z 0 )MRS(P k-2 |P k-3 |...|P 0 ) Observation: The MRS digit Z 0 is in units of 1, so fewer primes needed in MRS than in RNS

CSE Mixed Radix Number Systems  Question: what is the relationship between x 0 and Z 0 ? Can it be found by simple inspection? Yes. 1x 0 = Z 0. Why? x 0 is the residue left from x mod P 0 - all other terms are multiples of P 0 -> x 0 = Z 0

CSE Mixed Radix Number Systems  This yields 2x-x 0 = (x ’ k-1 |x ’ k-2 |...|x ’ 1 |-)RNS(P k-1 |P k-2 |...|P 1 |-) = (Z k-1 |Z k-2 |...|Z 1 |0)MRS(P k-2 |P k-3 |...|P 0 ) where x ’ i = (x i -x 0 ) p i Note that this is the only change in MRS

CSE Mixed Radix Number Systems  Which leads to 3(x-x 0 )/P 0 = (x ” k-1 |x ” k-2 |...|x ” 1 |-)RNS(P k-1 |P k-2 |...|P 1 |-) = (Z k-1 |Z k-2 |...|Z 1 ) MRS (P k-2 |P k-1 |...|P 1 ) Z 1 = x ” 1 and so forth. (Deduction, division, repeat) However, it was earlier noted that division in RNS is hard - yet here we are doing division. The trick? In this case, we know that we will always get integer results.

CSE Back to RNS  Division in RNS x ” i =x i * (P 0 -1 ) p i where (P j -1 ) p i is the multiplicative inverse of P j with respect to P i Ex:(3 -1 ) 7 = 5 --> (3*(3 -1 ) 7 ) 7 = 1 (3 -1 ) 5 = 2 --> (3*(3 -1 ) 5 ) 5 = 1

CSE Example: RNS -> MRS Y=(1|3|2)RNS(7|5|3) = (Z 2 |Z 1 |Z 0 )MRS(5|3) That is, Y = Z 2 *5*3+Z 1 *3+Z 0 by 1 (see slide #25) Z 0 = x 0 = 2 from 2 (see slide #26) we have y-x 0 = y-2 =(x ’ 2 |x ’ 1 |0)RNS(7|5|3) = (Z 2 |Z 1 |0)MRS(5|3) x ’ 2 = (x 2 -x 0 ) p 2 = (1-2) 7 = 6 x ’ 1 = (3-2) 5 = 1 y-2 = (6|1|0)RNS(7|5|3)=(Z 2 |Z 1 |0)MRS(5|3)

CSE Example continued. 3 (See slide #27) then gives (y-x 0 )/P 0 = (y-2)/3 = (x ” 2 |x ” 1 |-)RNS(7|5|3) = (Z 2 |Z 1 )MRS(5) then Q: How does one derive x ” 2 ? A: “ It ’ s hard. ” One has to try values one by one up to the modulus remembering that (3 -1 ) 7 = 5, (3 -1 ) 5 = 2 x ” 2 = (5*6) 7 = 2, x ” 1 =(1*2) 5 = 2 (y-2)/3 = (2|2|-)RNS(7|5|3) = (Z 2 |Z 1 )MRS(5)

CSE Ex. Cont. Apply 1 again, Z 1 =x ” 1 =2 gives by 2 (y-x 0 )/P 0 - x ” 1 = (x ”’ 2 |0|-)RNS(7|5|3) = (Z 2 |0)MRS(5) x ”’ 2 =(x ” 2 -2) 7 = (2-2) 7 = 0 (0|0|-)RNS(7|5|3)=(Z 0 |0)MRS(5) By 3 x ”” 2 = (x ”’ 2 *(5 -1 ) 7 ) 7 = 0 = Z 2 Yields final result (0|2|2)MRS(5|3)

CSE Ex. Concluded. Check correctness (0|2|2)MRS(5|3) = 0*5*3+2*3+2 = = 1, 8 5 = 3, 8 3 = 2 -> (1|3|2)RNS(7|5|3) Correct!  Closing remark / Moral of the examples - “ Inversion is key ”