Let 2
Let 2
Instructor:
Prof. Chung-Kuan Cheng
Topics:
Redundant Number Systems
Residue Number Systems
Mixed Radix Number Systems (as they
pertain to conversions of Residue
Number Systems)
CSE 246 2
Redundant Number Systems
Examine number systems that can be
characterized by the 3-tuple (r, , )
r : radix, [, ] : set of digits
CSE 246 3
Redundant Number Systems
Ex: (2,0,2)
Redundant - furthermore, minimally redundant
4 2 1
Addition example: 0 0 0 0
0 0 1 1
0 0 2 2
0 1 0 2
1 0 2 (6) 0 1 1 3
0 1 2 4
+1 1 1 (7) 0 2 0 4
0 2 1 5
2 1 3 [3 not in radix] 0 2 2 6
1 0 0 4
+ 1 1
2 2 1 = 4*2 + 2*2 +1 = 13 = 6+7
CSE 246 4
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
CSE 246 5
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 246 6
Redundant Number Systems
To formalize:
xi+1 xi where xi + yi = r*ti+1 + wi
+ yi+1 yi
ti+1 wi
ti+2 wi+1
ti+1 + wi+1
CSE 246 7
Redundant Number Systems
As xi and yi are in [, ] and xi + yi = r * ti+1 + wi+1
1 2 r*ti+1 + wi 2
/(r-1)
/(r-1)
For (2,0,2):
/(r-1) -> 2/(2-1)
/(r-1) -> 0/(2-1)
CSE 246 9
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 wi of [0,2]
CSE 246 10
Redundant Number Systems
Ex: for (3,0,5)
243
+435 5+3 = 8 could use 15, but choose from [0,2]
22 yielding 22 and no propagation
21
20
2232
CSE 246 11
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 246 12
Residue Number Systems
Define a Residue Number System as follows
CSE 246 13
Residue Number Systems
Need a conversion system to/from binary
Binary #
RNS
ops RNS #
+,-,*
Binary #
CSE 246 14
Residue Number Systems
Addition (subtraction is similar)
Multiplication
x*y = ((x1*y1)p | (x2*y2)p | ... | (xk*yk)p )RNS(P1|P2|...|Pk)
1 2 k
Division ?
Hard. What does a fraction look like in RNS?
CSE 246 15
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 246 16
Residue Number Systems
Conversion: RNS -> Binary #
Given (x1|x2|...|xk)RNS(P1|P2|..|Pk)
k
P j
Binary number x =
xi i
i 1 Pi
mod
P j
Pj P
,P i j See: Chinese
where i = inv Pi i Pi 1 Remainder Theorem
Pi
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 + 4*2*21 + 0)105
x = (4*1*21)105 = 84105
CSE 246 18
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*15+1*1*21+1*2*35)105=(106)105 = 1105
CSE 246 19
Residue Number Systems
Binary # Conversion -> Chinese remainder theorem
Binary #
Minimize:
total length of primes (determining range)
max length of any prime (determining HW
cost/delay per unit)
# of primes (determining # of parallel units)
CSE 246 20
Residue Number Systems
Binary # to RNS conversion
Uses a lookup table
Observation: for n digit binary number y
(yn-1,yn-2,...,y0)p = [(2n-1)p *yn-1+ (2n-2)p *yn-2+...+(20)p *y0]p
i i i i i
CSE 246 22
Mixed Radix Number
Systems
We shall describe a Mixed Radix System
as follows:
x =(Zk-1|Zk-2|...Z0)MRS(Pk-1|Pk-2|...|P1)
CSE 246 23
Mixed Radix Number
Systems
Conversion from RNS to MRS
Given x = (xk-1|xk-2|...|x0)RNS(Pk-1|Pk-2|...|P0)
We want x=(Zk-1|Zk-2|...|Z0)MRS(Pk-2|Pk-3|...|P0)
CSE 246 24
Mixed Radix Number
Systems
Question: what is the relationship
between x0 and Z0?
Yes.
1 x = Z .
0 0
Why?
x0 is the residue left from x mod P0 - all other
terms are multiples of P0 -> x0 = Z0
CSE 246 25
Mixed Radix Number
Systems
This yields
2 x-x0 = (x’k-1|x’k-2|...|x’1|-)RNS(Pk-1|Pk-2|...|P1|-)
= (Zk-1|Zk-2|...|Z1|0)MRS(Pk-2|Pk-3|...|P0)
CSE 246 26
Mixed Radix Number
Systems
Which leads to
3 (x-x0)/P0 = (x”k-1|x”k-2|...|x”1|-)RNS(Pk-1|Pk-2|...|P1|-)
= (Zk-1|Zk-2|...|Z1) MRS (Pk-2|Pk-1|...|P1)
Z1 = x”1
where
CSE 246 28
Example: RNS -> MRS
Y=(1|3|2)RNS(7|5|3) = (Z2|Z1|Z0)MRS(5|3)
That is, Y = Z2*5*3+Z1*3+Z0
Z0 = x0 = 2
x’1 = (3-2)5 = 1
y-2 = (6|1|0)RNS(7|5|3)=(Z2|Z1|0)MRS(5|3)
CSE 246 29
Example continued.
3 (See slide #27) then gives
'
7 A x
7 B x2" 7
then
2
3 7
Q: How does one derive x”2 ?
A: “It’s hard.” One has to try values one by one up to the
modulus
7 A x 21B 3x
'
2 7
"
2 7
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) = (Z2|Z1)MRS(5)
CSE 246 30
Ex. Cont.
Apply 1 again,
Z1=x”1=2
gives by 2
(y-x0)/P0 - x”1 = (x”’2|0|-)RNS(7|5|3) = (Z2|0)MRS(5)
By 3
y x0 " x””2 = (x”’2*(5-1)7)7 = 0 = Z2
x1
P0
...
P1 Yields final result
(0|2|2)MRS(5|3)
CSE 246 31
Ex. Concluded.
Check correctness
(0|2|2)MRS(5|3) = 0*5*3+2*3+2 = 8
87 = 1, 85 = 3, 83 = 2 -> (1|3|2)RNS(7|5|3)
Correct!
“Inversion is key”
CSE 246 32