Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Dr. Arunachalam V
Associate Professor, SENSE
Choosing the RNS moduli
• The set of moduli chosen for RNS affects both the representational
efficiency and the complexity of arithmetic algorithms.
• In general, we try to make the moduli as small as possible, since it is the
magnitude of the largest modulus mk-1 that dictates the speed of arithmetic
operations.
• We also often try to make all the moduli comparable in magnitude to the
largest one, since with the computation speed already dictated by mk-1,
there is usually no advantage in fragmenting the design of arithmetic unit
through the use of very small moduli at the right end.
Choosing the RNS moduli – using prime numbers
• Let us assume that we want to represent unsigned integers in the range (0 to
1,00,000)10 , requiring 17 bits with standard binary representation.
• RNS (13|11|7|5|3|2) ; M = 30,030
• Range is not yet adequate
• RNS (17|13|11|7|5|3|2) ; M = 5,10,510
• M is 5.1 times of the required range, Therefore the moduli 5 is removed,
• RNS (17|13|11|7|3|2) ; M = 1,02,102
• The number of bits needed for encoding each number is (5+4+4+3+2+1 =
19 bits)
• Now, since the speed of arithmetic operations is dictated by the 5-bit
residues modulo m5, we can combine the pairs of moduli 2 and 13 (26) & 3
and 7 (21), with no speed penalty.
• RNS (26|21|17|11) ; M = 1,02,102 ; This still needs 19 bits
Choosing the RNS moduli – using pairwise relatively prime
numbers
• If we precompute and store for each i & j, then the residue xi of y (mod mi)
can be computed by modulo- mi addition of these constants.
• For converting 10-binary numbers in the range[0,839] to RNS(8|7|5|3).
• Only residues mod 7, mod 5 and mod 3 are given in the table, since the
residue mod 8 is directly available as the 3 least significant bits of the
binary number y.
Precomputed residues of the first 10 powers of 2
Represent y = (1010 0100)2 = (164)10 in RNS(8|7|5|3).
• mod 8 is (100)2 = 4
• y = 27 + 25 + 22
• Answer : (4|3|4|2)
Optimizing the number of modulo additions
• In the worst case, k modular additions are required for computing each
residue of a k-bit number. To reduce the number of operations, one can
view the given input number as a number in a high radix.
• For example, if we use radix 4, then storing the residues of 4i, 2×4i & 3×4i
in a table would allow us to compute each of the required residues using
only k/2 modular additions.
• The conversion for each modulus can be done by repeatedly using a single
lookup table and modular adder or by several copies of each arranged into a
pipeline.
• For a low-cost modulus m = 2a-1, the residue can be by determined by
dividing up y into a-bit segments and adding them modulo 2a-1.
Conversion from RNS to binary/decimal
• First derive the mixed-radix representation of the RNS number
• Then use the weights of the mixed-radix positions to compute the
conversion
• Also derive position weights for the RNS directly based on the Chinese
remainder theorem (CRT).
• The Chinese remainder theorem
• The magnitude of an RNS number can be obtained from the CRT formula:
• Where, by definition,
The Chinese remainder theorem (CRT)
• The magnitude of an RNS number can be obtained from the CRT formula:
• = | ∙∙∙| | = ∑
• Where, by definition, = / , and = is the multiplicative
inverse of Mi with respect to mi.
Values needed in applying the CRT to RNS(8|7|5|3)
i
i
3 8 0 0
1 5 0 0
1 105
1 168
2 210
2 336
3 315
3 504
4 420
4 672
5 525
0 3 0 0
6 630
1 280
7 735
2 560
2 7 0 0
1 120
2 240
3 360
4 480
5 600
6 720
Example
(1|0|0|0)RNS = 105
(0|1|0|0)RNS = 120
(0|0|1|0)RNS = 168
(0|0|0|1)RNS = 280