Você está na página 1de 34

Overview of

Residue Number System (RNS)



for
Advanced VLSI Design and VLSI Signal
Processing

11-30-2002

NTUEE
Outline
History
Why RNS is needed ?
Fundamental concepts in RNS.
Conversion between Decimal and Residue.
Conventional complex RNS
Difficult arithmetic operations
Applications
History
The ancient study of the residue numbering
system begins with a verse from a third-
centry book, Suan-Ching, by Sun Tzu.
We have things of which we do not know the number,
If we count them by three, the remainder is 2,
If we count them by five, the remainder is 3,
If we count them by seven, the remainder is 2,
How many things are there?
History
We commemorate this contribution as the
Chinese Remainder Theorem, or CRT.
This theorem, as well as RNS, was set forth
in the 19th by Carl Friedrich Gauss in his
celebrated Disquisitiones Arithmetical.
Why RNS?
It is a carry-free system that performs
addition, substraction, and multiplication as
parallel operations.
FA FA FA HA FA
0 0
b a
1 1
b a
2 2
b a
3 3
b a
4 4
b a
0
s
1
s
2
s
3
s
4
s
out
c
Definition
The RNS is defined in terms of a set of rela-
tively prime moduli.
If P denotes the moduli set, then
{ }
L
p p p , , ,
2 1
= P
( ) j i for p p
j i
= = , 1 , GCD
The dynamic range M is
L
p p p M
2 1
=
Any integer in the residue class Z
M
has a
unique L-tuple representation given by
( )
L
RNS
X X X X , , ,
2 1

where X
i
=X mod p
i
and is called the ith residue.
Definition
{ } { } 5 , 3 ,
2 1
= = p p P
15 5 3 = = M
X
1

0
1
2
0
1
X
2

0
1
2
3
4


















X
1

2
0
1
2
0
X
2

0
1
2
3
4
X
1

1
2
0
1
2
X
2

0
1
2
3
4
X
0
1
2
3
4
5
6
7
8
9
X
10
11
12
13
14
X
Example
4
5
6
7
8
9
10
11
0
1
2
3
X












X
1

0
1
2
0
1
2
0
1
2
0
1
2
X
2

0
1
2
3
0
1
2
3
0
1
2
3
X
3

0
1
2
3
4
0
1
2
3
4
0
1
16
17
18
19
20
21
22
23
12
13
14
15
X












X
3

2
3
4
0
1
2
3
4
0
1
2
3
28
29
30
31
32
33
34
35
24
25
26
27
X












X
3

4
0
1
2
3
4
0
1
2
3
4
0
40
41
42
43
44
45
46
47
36
37
38
39
X












X
3

1
2
3
4
0
1
2
3
4
0
1
2
52
53
54
55
56
57
58
59
48
49
50
51
X












X
3

3
4
0
1
2
3
4
0
1
2
3
4
X
1

0
1
2
0
1
2
0
1
2
0
1
2
X
1

0
1
2
0
1
2
0
1
2
0
1
2
X
1

0
1
2
0
1
2
0
1
2
0
1
2
X
1

0
1
2
0
1
2
0
1
2
0
1
2
X
2

0
1
2
3
0
1
2
3
0
1
2
3
X
2

0
1
2
3
0
1
2
3
0
1
2
3
X
2

0
1
2
3
0
1
2
3
0
1
2
3
X
2

0
1
2
3
0
1
2
3
0
1
2
3
{ } { } 5 , 4 , 3 , ,
3 2 1
= = p p p P
60 5 4 3 = = M
Example
Signed Representation
For signed RNS, any integer in (-M/2, M/2],
has a unique RNS L-tuple representation
where x
i
=(X mod p
i
) if X>0, and (M-|X|)
mod p
i
otherwise.
{ } { } 4 , 3 ,
2 1
= = p p P
X
1

0
1
2
0
X
2

2
3
0
1















X
1

1
2
0
1
X
2

2
3
0
1
X
1

2
0
1
2
X
2

2
3
0
1
X
-6
-5
-4
-3
-2
-1
0
1
X
2
3
4
5
X
( )
( )
L
RNS
L
RNS
Y Y Y Y
X X X X
, , ,
, , ,
2 1
2 1



Y X Z =
( )
L
RNS
Z Z Z Z , , ,
2 1

tion multiplica and n subtractio addition, present
( ) = ( ) , mod
1 1 1
p Y X ( ) , mod
2 2 2
p Y X ( )
L L L
p Y X mod ,
Operation
7(1, 3, 2 )
+3(0, 3, 3 )
10(1 mod 3, 6 mod 4, 5 mod 5) = (1,2,0)
7(1, 3, 2 )
- 3(0, 3, 3 )
4(1 mod 3, 0 mod 4, -1 mod 5) = (1,0,4)
7(1, 3, 2 )
*3(0, 3, 3 )
21(0 mod 3, 9 mod 4, 6 mod 5) = (0,1,1)
Operation (Example)
4
5
6
7
8
9
10
11
0
1
2
3
X












X
1

0
1
2
0
1
2
0
1
2
0
1
2
X
2

0
1
2
3
0
1
2
3
0
1
2
3
X
3

0
1
2
3
4
0
1
2
3
4
0
1
16
17
18
19
20
21
22
23
12
13
14
15
X












X
3

2
3
4
0
1
2
3
4
0
1
2
3
28
29
30
31
32
33
34
35
24
25
26
27
X












X
3

4
0
1
2
3
4
0
1
2
3
4
0
40
41
42
43
44
45
46
47
36
37
38
39
X












X
3

1
2
3
4
0
1
2
3
4
0
1
2
52
53
54
55
56
57
58
59
48
49
50
51
X












X
3

3
4
0
1
2
3
4
0
1
2
3
4
X
1

0
1
2
0
1
2
0
1
2
0
1
2
X
1

0
1
2
0
1
2
0
1
2
0
1
2
X
1

0
1
2
0
1
2
0
1
2
0
1
2
X
1

0
1
2
0
1
2
0
1
2
0
1
2
X
2

0
1
2
3
0
1
2
3
0
1
2
3
X
2

0
1
2
3
0
1
2
3
0
1
2
3
X
2

0
1
2
3
0
1
2
3
0
1
2
3
X
2

0
1
2
3
0
1
2
3
0
1
2
3
{ } { } 5 , 4 , 3 , ,
3 2 1
= = p p p P
60 5 4 3 = = M
(3,4,5) Modulo Set
Efficient and rapid implementation of the
operation (X
i
o Y
i
) mod p
i
must be found.
Only for the case where p
i
=2^n can be
easily implemented in conventional system.
RAM or ROM
Table Lookup

Z
i
= (X
i
o Y
i
) mod p
i

X
i
(n bits)
Y
i
(n bits)
Z
i
(n bits)
Conversion
To be competitive system, the speed of data
acquisition and the accompanying decimal-
to-residue conversion must be equally fast.
Decimal-to-residue Conversion
( )

=

+ = =
1
0
0 1 2 1 ' 2
2 2
N
j
j
j
N
N N N comp s
b b b b b b b X
( ) ( ) ( )
i
N
j
i
j
j i
N
i N
i i
p p b p p b
p X X
mod mod 2 mod 2
mod
1
0
(

+ =

=
Decimal-to-residue Conversion
( ) ( )
binary decimal
X 011101 29 = = ( ) ( ) 7 , 5 ,
2 1
= = p p P
( ) 4 5 mod 1 1 2 0 4 1 3 1 1 1 3 0
1
= + + + + + = X
( ) 1 7 mod 1 1 2 0 4 1 1 1 2 1 3 0
2
= + + + + + = X
2
j
mod p
i
j=4
i=1
i=2
j=3 j=2 j=1 j=0
1 3 4 2 1
2 1 4 2 1
p
i
-(2
5
mod p
i
)
i=1
i=2
3
3
( ) ( ) ( )
(

=
1
0
mod 2 mod 2
N
j
i
j
j i
N
i N
p b p p b
Generally speaking, the speed limitation of
residue-to-decimal conversion is a problem
in residue number system.

The R/D problem can be solved in one of
the following two ways:
Mixed radix conversion (MRC)
Chinese Remainder Theorem (CRT)
Residue-to-decimal Conversion
Multiplicative Inverse
The multiplicative inverse of g of modulo p
i

is denoted as g
i
-1
and satisfies
( ) 1 mod
1
=

i i
p g g
Example:
P
i
=5
g
g
i
-1

0
X
1
1
2
3
3
2
4
4
g
g
i
-1

P
i
=6
0
X
1
1
2
X
3
X
4
X
5
5
g
g
i
-1

P
i
=7
0
X
1
1
2
4
3
5
4
2
5
3
6
6
Mixed Radix Conversion
X ( )
L
X X X , , ,
2 1

RNS
( )
L
X X X

, ,

2 1

MRC
The MRC representation is given by
( ) M X v X v X v X
L L
mod

2 2 1 1
+ + + =
where v
1
=1, v
2
=p
1
, v
3
=p
1
p
2
, v
4
=p
1
p
2
p
3
,
Mixed radix conversion
L L
L L
X p p p X p p X p X
X v X v X v X v X


1 2 1 3 2 1 2 1 1
3 3 2 2 1 1

+ + + + =
+ + + + =

1 1 1

mod X X p X = =
( )
L L
L L
X p p X p X X X p
X p p p X p p X p X X


1 2 3 2 2 1
1
1
1 2 1 3 2 1 2 1 1


+ + + =
+ + + =


( ) | |
2 2 1
1
2 , 1

mod

X p X X p =

( ) | |
2 2 1 2
1
2 , 1

mod X p X X p =

Mixed Radix Conversion


( )
( ) | |
( ) | | { }
3 3 2 1
1
3 , 1
1
3 , 2
1 3 4 3 3 2 1
1
1
1
2
1 2 4 3 2 3 2 2 1
1
1

mod



X p X X X p p
X p p X p X X X X p p
X p p X p p X p X X X p
L L
L L
=
+ + + =
+ + + =





( ) | | { }
3 3 2 1 3
1
3 , 1
1
3 , 2

mod

X p X X X p p =

Use nesting subtractions and multiplicative
inverse to make sequential conversion.
Block Diagram of MRC
p
12
-1

p
13
-1
M
M
p
1L
-1
M
p
23
-1
M
p
2L
-1
M p
L-1,L
-1
M
1
X
2
X
3
X
L
X
1

X
2

X
3

X
L
X

Chinese Remainder Theorem


( ) | | M p s X s X
L
i
i i i i
mod mod
1
1
)
`

=

=

where

and s
i
-1
is the multiplicative
inverse of s
i
mod p
i
, so that
( ) 1 mod
1
=

i i i
p s s
L i i
i
i
p p p p p
p
M
s = =
+

1 1 2 1
Chinese Remainder Theorem
( ) | | M p s X s X
L
i
i i i i
mod mod
1
1
)
`

=

=

X
1
s
1
-1
mod p
1

X
2
s
2
-1
mod p
2

X
L
s
L
-1
mod p
L

mod M
1
X
2
X
L
X
X
s
L

s
2

s
1

Chinese Remainder Theorem
{ } { } 5 , 4 , 3 , ,
3 2 1
= = p p p P
60 5 4 3 = = M
( )
( )
( )

= = = =
= = = =
= = = =



1 mod . . 3 12 5
1 mod . . 3 15 4
1 mod . . 2 20 3
3 3
1
3
1
3 3 3
2 2
1
2
1
2 2 2
1 1
1
1
1
1 1 1
p s s t s s s p
p s s t s s s p
p s s t s s s p
( ) 4 , 0 , 1 = X
1*2 mod 3
0*3 mod 4
4*3
mod 5
20
15
12
mod 60
4 = X
Conventional Complex RNS
( )
M M L
RNS
Z Y Z X Z Z Z jY X Z e e + = , ; , , ,
2 1

A complex number Z is defined to be
( ) ( ) ( )
i i i
p Y j p X Z mod mod + =
( )
L
Z Z Z Z Z Z
3 32 31 2 1 3
, , , = + =
( ) ( )
i i i i i
Y Y j X X Z
2 1 2 1 3
+ + + =
( )
L
Z Z Z Z Z Z
3 32 31 2 1 3
, , , = - =
( ) ( )
i i i i i i i i i
Y X Y X j Y Y X X Z
1 2 2 1 2 1 2 1 3
+ + =
Difficult Arithmetic Operations
Magnitude comparison / Sign detection
Division
Base extension
Scaling / Rounding / Truncation
Overflow detection
Magnitude Comparison
Sign Detection
Not a weighted number system.
Every digits are equally important.
( ) ( ) ( ) 3 , 3 , 3 0 , 1 , 1 3 , 3 , 2 = = = Z Y X
? 6 ? 0 ? > > > Z Y Y X
The problem makes the RNS-based signal
processors inefficient.
Division
Blend of nested subtractions and magnitude
comparisons, so it is more difficult in the
RNS domain.
RNS is not closed under division, since the
RNS is an integer system.
It is an slow, high-overhead operation, and
should be avoided in RNS.


Base Extension
Increase the dynamic range
Increase the resolution.
R/D and D/R conversions are needed.
R/D conversion
L - tuple RNS
D/R conversion
K - tuple RNS
Moduli
extension
Scaling / Rounding / Truncation
Prevent dynamic-range overflow.
A special form of division.
The scaling operation can be easily to
implemented when scaling factor is:
Power of two (2
n
) in 2complement.
Product of one or more of the moduli in RNS.
Overflow Detection
A special form of magnitude comparison.
Can be avoided by using scaling operation
during run-time.
Applications
High-speed systems
(**) FPGA-based solution
Filtering (FIR, IIR) systems
Linear transformations
Adaptive systems
References
[1] A good tutorial paper of RNS: Fred J. Taylor,
"Residue Arithmetic: A Tutorial with Examples",
IEEE Trans. on Computer, pp. 50~62, May 1984.
[2] A good paper collections for RNS: M. A.
Soderstrand, W. K. Jenkins, G. A. Jullien, F. J.
Taylor (eds.), Residue Number System Arithmetic:
Modern Applications in digital Signal Processing,
IEEE Press, New York, 1986.

Você também pode gostar