CSE 246: Computer Arithmetic Algorithms and Hardware Design - PowerPoint PPT Presentation

About This Presentation
Title:

CSE 246: Computer Arithmetic Algorithms and Hardware Design

Description:

Uses a lookup table. Observation: for n digit binary number y ... Correct! Closing remark / Moral of the examples - 'Inversion is key' ... – PowerPoint PPT presentation

Number of Views:86
Avg rating:3.0/5.0
Slides: 33
Provided by: haiku
Learn more at: https://cseweb.ucsd.edu
Category:

less

Transcript and Presenter's Notes

Title: CSE 246: Computer Arithmetic Algorithms and Hardware Design


1
CSE 246 Computer Arithmetic Algorithms and
Hardware Design
Fall 2006 Lecture 2 Redundant and residue number
systems
  • Instructor
  • Prof. Chung-Kuan Cheng

2
Topics
  • Redundant Number Systems
  • Residue Number Systems
  • Mixed Radix Number Systems (as they pertain to
    conversions of Residue Number Systems)

3
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 ? - ? 1 r
  • redundant if ? - ? 1 gt r
  • minimally redundant if ? - ? r
  • maximally redundant if ? - ? 2r - 1
  • over redundant if ? - ? gt 2r - 1

4
Redundant Number Systems
  • Ex (2,0,2)
  • Redundant - furthermore, minimally redundant
  • Addition example
  • 1 0 2 (6)
  • 1 1 1 (7)
  • 2 1 3 3 not in radix
  • 1 1
  • 2 2 1 42 22 1 13 67

5
Redundant Number Systems
  • More addition examples
  • 110 121 101121 111222
  • 102 101 112210 112222
  • 212 222 111 20
  • 11 20
  • 11 20
  • 21 11
  • 222211 22
  • 11220
  • 11
  • 2
  • 1121220

6
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

7
Redundant Number Systems
  • To formalize
  • xi1 xi where xi yi rti1 wi
  • yi1 yi
  • ti1 wi
  • ti2 wi1
  • ti1 wi1 we
    must bound ti1 wi1 for all i to eliminate
    carry propagation

8
Redundant Number Systems
  • As xi and yi are in ?, ? and xi yi r ti1
    wi1
  • 2? ? rti1 wi ? 2?
  • suppose there exist ? and ? such that
  • ? ? ti1 ? ?
  • we need
  • ? - ? ? wi1 ? ? - ?
  • to avoid propagation. Since this must be true
    for all i, whether the subscript is i or i1 is
    not important.
  • From 2 3 we have
  • r? ? - ? ? rti1 wi1 ? r? ? - ?
  • From 1 4 we have
  • 2? ? r? ? - ?

9
Redundant Number Systems
  • 2? ? r? ? - ?
  • gives the following bounds for ? ? to insure no
    propagation
  • ? ? ?/(r-1)
  • ? ? ?/(r-1)
  • For (2,0,2)
  • ? ? ?/(r-1) -gt ? ? 2/(2-1)
  • ? ? ?/(r-1) -gt ? ? 0/(2-1)
  • which, from 3 means all wi must be in the range
    0,0 and there exist inputs requiring carry
    propagation

10
Redundant Number Systems
  • How then to ensure that no carry propagation is
    needed?
  • Change (r, ?, ?)
  • Consider (3,0,5)
  • ? ? ?/(r-1) -gt ? ? 5/(3-1)
  • ? ? ?/(r-1) -gt ? ? 0/(3-1) yields
  • ? 3 (first integer after 5/2)
  • ? 0
  • From 3, this gives a range on wi 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

11
Redundant Number Systems
  • Ex for (3,0,5)
  • 243
  • 435 53 8 could use 15, but choose from 0,2
  • 22 yielding 22 and no propagation
  • 21
  • 20
  • 2232

12
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

13
Residue Number Systems
  • Define a Residue Number System as follows
  • For any given integer x, x(x1x2...xk)RNS(P1P2
    ...Pk)
  • where xi x mod Pi and ? i,j Pi is relatively
    prime to Pj
  • EX 84 (040)RNS(753) 1
    (111)RNS(753)
  • 2 (222)RNS(753)
  • 3 (330)RNS(753)
  • Residue numbers are not positional.
  • Residue numbers have unique representations mod
  • i.e. for (753) there are unique representations
    of 0-104.

14
Residue Number Systems
  • Need a conversion system to/from binary
  • What benefits of doing operations in RNS?

Binary
RNS ops ,-,
RNS
Binary
15
Residue Number Systems
  • Addition (subtraction is similar)
  • xy ((x1y1)p1 (x2y2)p2 ...
    (xkyk)pk)RNS(P1P2...Pk)
  • where xi (x)pi and yi (y)pi
  • Multiplication
  • xy ((x1y1)p1 (x2y2)p2 ...
    (xkyk)pk)RNS(P1P2...Pk)
  • where xi (x)pi and yi (y)pi
  • Division ?
  • Hard. What does a fraction look like in RNS?

16
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 (753) to (7532) where
    last field is used for parity)
  • Disadvantages
  • No division
  • Comparison non-trivial
  • Conversion costs
  • How to do conversion?

17
Residue Number Systems
  • Conversion RNS -gt Binary
  • Given (x1x2...xk)RNS(P1P2..Pk)
  • 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
18
Residue Number Systems
  • Conversion -gt Bin example
  • 84 (040)RNS(753)
  • For (753) (?1 53)7 1 ? ?1 1 (?2 73)5
    1 ? ?2 1 (?3 75)3 1 ? ?3 2
  • x (0?1537/7 4?2735/5
    0?3753/3)105
  • x (0 4?221 0)105
  • x (4121)105 84105

19
Residue Number Systems
  • Conversion -gt Bin example
  • 1 (111)RNS(753) (?1 53)7 1 ? ?1 1
    (?2 73)5 1 ? ?2 1 (?3 75)3 1 ? ?3 2
  • x (1?1537/7 1?2735/5
    1?3753/3)105
  • x (1?115 1?221 1?335)105
  • x (111511211235)105(106)105 1105

20
Residue Number Systems
Conversion -gt Chinese remainder theorem
Binary
RNS ops ,-,
How to choose primes?
RNS
  • 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 2r-1 (2,3 particularly popular)
  • Thm 2a-1 2b-1 are relatively prime iff a b
    are relatively prime

Binary
What about Bin -gt RNS?
21
Residue Number Systems
  • Binary to RNS conversion
  • Uses a lookup table
  • Observation for n digit binary number y
    (yn-1,yn-2,...,y0)pi (2n-1)piyn-1
    (2n-2)piyn-2...(20)piy0pi
  • Use a table to store (2i)pi
  • Example for (753)
  • (1011)(x1x2x3)RNS(753)
  • x1 (121)7 4
  • x2 (321)5 1
  • x3 (221)3 2

22
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.

23
Mixed Radix Number Systems
  • We shall describe a Mixed Radix System as
    follows
  • x (Zk-1Zk-2...Z0)MRS(Pk-1Pk-2...P1)
  • x Zk-1Pk-1Pk-2...P1 Zk-2Pk-2Pk-1...P0 ...
    Z1P1Z0

24
Mixed Radix Number Systems
  • Conversion from RNS to MRS
  • Given x (xk-1xk-2...x0)RNS(Pk-1Pk-2...P0)
  • We want x(Zk-1Zk-2...Z0)MRS(Pk-2Pk-3...P0)
  • Observation The MRS digit Z0 is in units of 1,
    so
  • fewer primes needed in MRS than in RNS

25
Mixed Radix Number Systems
  • Question what is the relationship between x0 and
    Z0?
  • Can it be found by simple inspection?
  • Yes.
  • x0 Z0.
  • Why?
  • x0 is the residue left from x mod P0 - all other
    terms are multiples of P0 -gt x0 Z0

26
Mixed Radix Number Systems
  • This yields
  • x-x0 (xk-1xk-2...x1-)RNS(Pk-1Pk-2...P1
    -) (Zk-1Zk-2...Z10)MRS(Pk-2Pk-3..
    .P0)where xi (xi-x0)pi Note
    that this is the only change in MRS

27
Mixed Radix Number Systems
  • Which leads to
  • (x-x0)/P0 (xk-1xk-2...x1-)RNS(Pk-1Pk-2.
    ..P1-) (Zk-1Zk-2...Z1) MRS
    (Pk-2Pk-1...P1)Z1 x1 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.

28
Back to RNS
  • Division in RNS
  • xi xi (P0-1)pi
  • where
  • (Pj-1)pi is the multiplicative inverse of Pj
    with respect to Pi
  • Ex (3-1)7 5 --gt (3(3-1)7)7 1 (3-1)5 2
    --gt (3(3-1)5)5 1

29
Example RNS -gt MRS
  • Y(132)RNS(753) (Z2Z1Z0)MRS(53)
  • That is, Y Z253Z13Z0
  • by 1 (see slide 25)
  • Z0 x0 2
  • from 2 (see slide 26) we have
  • y-x0 y-2 (x2x10)RNS(753)
    (Z2Z10)MRS(53)
  • x2 (x2-x0)p2 (1-2)7 6
  • x1 (3-2)5 1
  • y-2 (610)RNS(753)(Z2Z10)MRS(53)

30
Example continued.
  • 3 (See slide 27) then gives
  • (y-x0)/P0 (y-2)/3 (x2x1-)RNS(753)
    (Z2Z1)MRS(5)
  • then
  • Q How does one derive x2 ?
  • A Its hard. One has to try values one by one
    up to the modulus
  • remembering that (3-1)7 5, (3-1)5 2
  • x2 (56)7 2, x1 (12)5 2
  • (y-2)/3 (22-)RNS(753) (Z2Z1)MRS(5)

31
Ex. Cont.
  • Apply 1 again,
  • Z1x12
  • gives by 2
  • (y-x0)/P0 - x1 (x20-)RNS(753)
    (Z20)MRS(5)
  • x2 (x2-2)7 (2-2)7 0
  • (00-)RNS(753)(Z00)MRS(5)
  • By 3
  • x2
    (x2(5-1)7)7 0 Z2
  • Yields final result
  • (022)MRS(53)

32
Ex. Concluded.
  • Check correctness
  • (022)MRS(53) 053232 8
  • 87 1, 85 3, 83 2 -gt (132)RNS(753)
  • Correct!
  • Closing remark / Moral of the examples
    -Inversion is key
Write a Comment
User Comments (0)
About PowerShow.com