0% found this document useful (0 votes)
49 views

Residual Number System

gi-1 does not always exist. It exists if and only if g and pi are relatively prime. gi-1 Χ 1 5 3 6 Χ Χ 台灣大學 吳安宇 教授 ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU Applications ™Digital Signal Processing (DSP) ™Filtering and convolution ™Fast Fourier Transform (FFT) ™Digital Communication ™Error Correction Coding ™Cryptography ™Finite Field Arithmetic ™ECC for Public Key Cryptosystem ™Modular Exponentiation ™

Uploaded by

Dlisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Residual Number System

gi-1 does not always exist. It exists if and only if g and pi are relatively prime. gi-1 Χ 1 5 3 6 Χ Χ 台灣大學 吳安宇 教授 ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU Applications ™Digital Signal Processing (DSP) ™Filtering and convolution ™Fast Fourier Transform (FFT) ™Digital Communication ™Error Correction Coding ™Cryptography ™Finite Field Arithmetic ™ECC for Public Key Cryptosystem ™Modular Exponentiation ™

Uploaded by

Dlisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Graduate Institute of Electronics Engineering, NTU

Overview of
Residue Number System ((RNS)
RNS)

for Advance VLSI Design

NTUEE 吳安宇 教授

ACCESS IC LAB
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Outline
™History
™Why RNS is needed ?
™Fundamental concepts in RNS.
™Conversion between Decimal and Residue.
™Conventional complex RNS
™Difficult arithmetic operations
™Applications

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

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 thins of which we do not know the number,


If we count them by three, the remainder is 2,
If we count them by fives, the remainder is 3,
If we count them by sevens, the remainder is 2,
How many things are there?

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

History
™We commemorate this contribution as the
Chinese Remainder Theorem (CRT).

™This theorem, as well as RNS, was set forth


in the 19th by Carl Friedrich Gauss in his
celebrated Disquisitions Arithmetical

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Why RNS is needed ?


™It is a “carry-free” system that performs
addition, subtraction, and multiplication as
parallel operations.

a4 b4 a3 b3 a2 b2 a1 b1 a0 b0

FA FA FA FA HA

cout s4 s3 s2 s1 s0

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Background
™The RNS is defined in terms of a set of
relatively prime moduli.
™If P denotes the moduli set, then
P = {p1 , p2 , , pL }
GCD( pi , p j ) = 1, for i ≠ j
™The dynamic range M is

M = p1 p2 pL

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Background
™Any integer in the residue class ZM has a
unique L-tuple representation given by

 ( X 1, X 2 ,
X →RNS
, XL)
where Xi=X mod pi and is called the ith
residue.

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Background

P = {p1 , p2 } = {3,5} M = 3 × 5 = 15
X → X1 X2 X → X1 X2 X → X1 X2
0 → 0 0 5 → 2 0 10 → 1 0
1 → 1 1 6 → 0 1 11 → 2 1
2 → 2 2 7 → 1 2 12 → 0 2
3 → 0 3 8 → 2 3 13 → 1 3
4 → 1 4 9 → 0 4 14 → 2 4

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Background
P = {p1 , p2 , p3 } = {3,4,5} M = 3 × 4 × 5 = 60
X → X1 X2 X3 X → X1 X2 X3 X → X1 X2 X3 X → X1 X2 X3 X → X1 X2 X3
0 → 0 0 0 12 → 0 0 2 24 → 0 0 4 36 → 0 0 1 48 → 0 0 3
1 → 1 1 1 13 → 1 1 3 25 → 1 1 0 37 → 1 1 2 49 → 1 1 4
2 → 2 2 2 14 → 2 2 4 26 → 2 2 1 38 → 2 2 3 50 → 2 2 0
3 → 0 3 3 15 → 0 3 0 27 → 0 3 2 39 → 0 3 4 51 → 0 3 1
4 → 1 0 4 16 → 1 0 1 28 → 1 0 3 40 → 1 0 0 52 → 1 0 2
5 → 2 1 0 17 → 2 1 2 29 → 2 1 4 41 → 2 1 1 53 → 2 1 3
6 → 0 2 1 18 → 0 2 3 30 → 0 2 0 42 → 0 2 2 54 → 0 2 4
7 → 1 3 2 19 → 1 3 4 31 → 1 3 1 43 → 1 3 3 55 → 1 3 0
8 → 2 0 3 20 → 2 0 0 32 → 2 0 2 44 → 2 0 4 56 → 2 0 1
9 → 0 1 4 21 → 0 1 1 33 → 0 1 3 45 → 0 1 0 57 → 0 1 2
10 → 1 2 0 22 → 1 2 2 34 → 1 2 4 46 → 1 2 1 58 → 1 2 3
11 → 2 3 1 23 → 2 3 3 35 → 2 3 0 47 → 2 3 2 59 → 2 3 4

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Background
™For signed RNS, any integer in (-M/2, M/2],
has a unique RNS L-tuple representation
™where xi=(X mod pi) if X>0,
™and (M-|X|) mod pi otherwise.

P = {p1 , p2 } = {3,4}
X → X1 X2 X → X1 X2 X → X1 X2
-6 → 0 2 -2 → 1 2 2 → 2 2
-5 → 1 3 -1 → 2 3 3 → 0 3
-4 → 2 0 0 → 0 0 4 → 1 0
-3 → 0 1 1 → 1 1 5 → 2 1

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Background

→( X 1 , X 2 ,
X RNS
 , XL)
→(Y1 , Y2 ,
Y RNS
 , YL )

Z=X Y
present addition, subtractio n and multiplica tion
→(Z1 , Z 2 ,
Z RNS
 , ZL )

= (( X 1 Y1 ) mod p1 ,( X 2 Y2 ) mod p2 , , ( X L YL ) mod pL )

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

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

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Background

™Efficient and rapid implementation of the


operation (Xi o Yi) mod pi must be found.
Only for the case where pi=2n can be easily
implemented in conventional system.

Xi (n bits)
RAM or ROM
Zi (n bits)
Table Lookup
Yi (n bits)
Zi = (Xi o Yi) mod pi

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Decimal-to-residue conversion
™To be competitive system, the speed of data
acquisition and the accompanying decimal-to-
residue conversion must be equally fast.
N −1
X 2 's −comp = (bN bN −1 b2b1b0 ) = −bN 2 N + ∑ b j 2 j
j =0

X i ≡ X mod pi
 N −1

= bN ( pi − (2 mod pi )) + ∑ b j (2 mod pi ) mod pi
N j

 j =0 

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Decimal-to-residue conversion
P = ( p1 , p2 ) = (5,7 ) X = (29 )decimal = (011101)binary
 N −1

bN ( pi − (2 mod pi )) + ∑ b j (2 mod pi )
N j

 j =0 
pi-(25mod pi) 2j mod pi j=4 j=3 j=2 j=1 j=0
i=1 3 i=1 1 3 4 2 1
i=2 3 i=2 2 1 4 2 1

X 1 = (0 ⋅ 3 + 1 ⋅ 1 + 1 ⋅ 3 + 1 ⋅ 4 + 0 ⋅ 2 + 1 ⋅ 1) mod 5 = 4
X 2 = (0 ⋅ 3 + 1 ⋅ 2 + 1 ⋅ 1 + 1 ⋅ 4 + 0 ⋅ 2 + 1 ⋅ 1) mod 7 = 1

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Residue-to-decimal conversion

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

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Multiplicative inverse
™The multiplicative inverse of g of modulo pi is
denoted as gi-1 and satisfies
(g g ) mod p
−1
i i =1
g 0 1 2 3 4
Pi=5
gi-1 Χ 1 3 2 4

Example: g 0 1 2 3 4 5
Pi=6
gi-1 Χ 1 Χ Χ Χ 5

g 0 1 2 3 4 5 6
Pi=7
gi-1 Χ 1 4 5 2 3 6

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Mixed radix conversion

X
RNS
( X 1, X 2 , , XL)

(Xˆ , Xˆ ,
1 2 , Xˆ L ) MRC

™The MRC representation is given by

(
X = v1 Xˆ 1 + v2 Xˆ 2 + + vL Xˆ L mod M)
where v1=1, v2=p1, v3=p1p2, v4=p1p2p3, …
台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Mixed radix conversion


X = v1 Xˆ 1 + v2 Xˆ 2 + v3 Xˆ 3 + + vL Xˆ L
= Xˆ 1 + p1 Xˆ 2 + p1 p2 Xˆ 3 + + p1 p2 … pL−1 Xˆ L

X mod p1 = X 1 = Xˆ 1

X − Xˆ 1 = p1 Xˆ 2 + p1 p2 Xˆ 3 + + p1 p2 … pL−1 Xˆ L
( )
⇒ p1−1 X − Xˆ 1 = Xˆ 2 + p2 Xˆ 3 + + p2 … pL−1 Xˆ L
⇒ [p (X − Xˆ )]mod p
−1
1, 2 1 2 = Xˆ 2

[p ( X
−1
1, 2 2 ]
− X 1 ) mod p2 = Xˆ 2

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Mixed radix conversion


( )
p1−1 X − Xˆ 1 − Xˆ 2 = p2 Xˆ 3 + p2 p3 Xˆ 4 + + p2 … pL−1 Xˆ L
[ ( ) ]
⇒ p2−1 p1−1 X − Xˆ 1 − Xˆ 2 = Xˆ 3 + p3 Xˆ 4 + + p3 … pL−1 Xˆ L
{ [ ( ) ]}
⇒ p −1 p −1 X − Xˆ − Xˆ
2,3 1, 3 1 mod p = Xˆ
2 3 3

{ p [p (X − Xˆ ) − Xˆ ] } mod p
−1
2,3
−1
1, 3 3 1 2 3 = Xˆ 3

™Use nesting subtractions and multiplicative


inverse to make sequential conversion.

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Mixed radix conversion


X1 X̂ 1

X2 X̂ 2
p12-1 M

X3 X̂ 3
p13-1 M p23-1 M

XL X̂ L
p1L-1 M p2L-1 M pL-1,L-1 M

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Chinese Remainder Theorem

L
[
X = ∑ si (X i si )mod pi
−1
]
 mod M
 i =1 
where si=M/pi and si-1 is the multiplicative
inverse of si mod pi, so that

(s s )mod p
−1
i i i =1

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Chinese Remainder Theorem

L
[
X = ∑ si (X i si )mod pi
−1
]
 mod M
 i =1 
X1
X1 s1-1 mod p1 s1
X2
X2 s2-1 mod p2 s2
X
mod M

XL
XL sL-1 mod pL sL

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Chinese Remainder Theorem


P = {p1 , p2 , p3 } = {3,4,5} M = 3 × 4 × 5 = 60

 p1 = 3 s1 = 20 ⇒ s1−1 = 2 s.t. (s1−1s1 )mod p1 = 1



p
 2 = 4 s2 = 15 ⇒ s −1
2 = 3 s.t . (s2 s2 ) mod p2 = 1
−1

 p = 5 s = 12 ⇒ s −1 = 3 s.t. (s −1s )mod p = 1


 3 3 3 3 3 3

1*2 mod 3 20
X =4
X = (1,0,4 ) 0*3 mod 4 15 mod 60

4*3 mod 5 12

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Conventional complex RNS


A complex number Z is defined to be

Z = X + jY RNS →(Z1 , Z 2 , , Z L ); X ∈ Z M , Y ∈ Z M

Z i = (( X mod pi ) + j (Y mod pi ))
Z 3 = Z1 + Z 2 = (Z 31 , Z 32 , , Z 3L )
Z 3i = ( X 1i + X 2i ) + j (Y1i + Y2i )
Z 3 = Z1 ∗ Z 2 = (Z 31 , Z 32 , , Z 3L )
Z 3i = ( X 1i X 2i − Y1iY2i ) + j ( X 1iY2i + X 2iY1i )

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Difficult arithmetic operations


™Magnitude comparison / Sign detection
™Division
™Base extension
™Scaling / Rounding / Truncation
™Overflow detection

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Magnitude comparison
Sign Detection
X = (2,3,3) Y = (1,1,0 ) Z = (3,3,3)
X >Y ? Y > 0? Z > 6?
™Not a weighted number system.
™Every digits are equally important.

The problem makes the RNS-based signal processors


inefficient.

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Division
™Blend of nested subtractions and magnitude
comparisons, so it is more difficult in the RNS.

RNS is not closed under division, since the RNS is an


integer system, it is.

Slow, high-overhead operation and should be avoided


in RNS.

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Base extension
™Increase the dynamic range
™Increase the resolution.

R/D and D/R conversions are needed.

L - tuple RNS K - tuple RNS

Moduli
R/D conversion extension
D/R conversion

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Scaling / Rounding / Truncation


™Prevent dynamic-range overflow.
™A special form of division.

The scaling operation is easily to implement when


scaling factor is:
power of two (2n) in 2’complement.
product of one or more of the moduli in RNS.

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Overflow detection
™Take the form of magnitude comparison.
™To be avoided by using scaling operation
during run-time.

台灣大學 吳安宇 教授
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU

Applications
™Filtering (FIR, IIR)
™Adaptive system
™Linear transformations

台灣大學 吳安宇 教授

You might also like