RESIDUE NUMBER SYSTEM (introduction to hardware asects) Dr. Danila Gorodecky danila.gorodecky@gmail.com
Terminology Residue number system (RNS) (refers to Chinese remainder theorem) Residue numeral system (RNS) Modular arithmetic (MA) (refers to moduli X (mod P) ) Comlete residue system Clock arithmetic (refers to -hour arrow clock in which numbers "wra around uon reaching the modulo)
Milestones Chinese mathematician Sunzi Suanjing roosed a theorem (Chinese remainder theorem) in the 3rd century AD; the theorem was generalized by Chinese mathematician Qin Jiushao in 47; first real imlementation of the theorem by German mathematician Carl Gauss in 80 "to find the years that have a certain eriod number with resect to the solar and lunar cycle and the Roman indiction ; first imlementation in comuter science by Czechoslovakian engineer Miro Valach in 955 Origin of the code and number system of remainder classes, Stroje Na ZracovaniInformaci, vol. 3, Nakl. CSAV, Prague.
Imlementation of RNS Processing of results of the Unified State Exam (utilized to entrance to University in Russia; Digital filternig with finite imulse resonse (FIR-filtering); Cryto system of Federal Reserve System of USA; Air Defense System (USA, Russia); crytograhy in Sace (Russia); Sace flight control (Russia) 4
Chinese remainder theorem Let s,,..., n are ositive integers (are often called as moduli) such, that greatest common divisor for a coule i j equals. Then the system, yx yx... mod mod yx n mod n has a simultaneous solution which is unique modulo,..., n, 5
Examle for the Theorem P 579 3 35 We can exress an arbitrary number definitely in the scoe from 0 to 34 Let s A00, hence A000 A00 A00 mod 5 mod 7 mod 9 and A 0,, in the RNS reresentation 6
NOT ositional numeral system RNS is not ositional numeral system 00(mod 5), 00(mod 7), 00(mod 9) (0,, ) 00 00(mod 7), 00(mod 9), 00(mod 5) (,, 0) 00 Binary system (0000) (0000) 00 5 0 0 7
Examle of the comutation in RNS P 579 3 AB003S 35 ) A0,, B3,6,4 ) A B 0 3 mod 5, 6 mod 7, 4 mod 9 3 mod 5, mod 7, 5 mod 9 3,,5 8
Y i 3) Examle of the comutation in RNS S SY S Y S3 Y3 r P P ki ; Y i (mod i ); i i r P S Y S Y S Y r P 3 3 a) 35 Y k 63 k 5 35 b) Y k 45 k 7 35 с) Y3 k3 35 k 9 3 63 k 5 (mod 5) and, then k and Y 6 k and, then and Y 5 45 (mod 7 35 k 3 (mod 9 7) 9) k 5 and, then k 3 8 andy 3 80 d) 35 r 35 36 8 5 5 80 r r, then 6 S 36 8 5 5 80 635 003 890 3
Exercises ) What is maximum bit range of A and B should be chosen for unambiguous reresentation A + B = S in RNS with moduli,3, and 5? P = * 3 * 5 = 45 0 S < 45 and S is -bit number. Hence, in order to reresent A + B = S, A and B should be limited -bit tules, when A and B both equal 077. ) What is maximum bit range of A, B, and C can be used for unambiguous reresentation A * B * C = R in RNS with moduli,3, and 5? P = * 3 * 5 = 45 0 S < 45 and S is -bit number. Hence, in order to reresent A * B * C = R, A, B, and C should be limited 4-bit tules, when A, B, and C equal. 0
Main advantage of RNS Significantly smaller ranges of numbers in arithmetic calculations than initial numbers
Examle of the comutation in RNS A B i i A { A, A, A3} (mod i ) A 0A34 A i B { B, B, B3} B (mod i ) B i 0B34 i i SSY SY S3Y 3rP Yi (mod i ) i Yi P i k i i,,3 k i, i r 0,,,...
X (mod P) hardware calculations in RNS X mod P A A Converter of A A g summator/multilier (mod ) S Converter of A ositional numbers to A A A g summator/multilier (mod ) S modular reresentation to S A g modular reresentation () A A summator/multilier (mod m ) S m ositional number () A g 3
4 Pielining aroach of X (mod P) calculations ) Pielining (iterative) aroach. It is based on the formula: A q P q P q P A Q P X 0 0......,,, x x x X...,,, P P P
50 Pielining aroach of X (mod P) calculations mod7 7Q Amod7 6 5 4 3 0 7 q6 7 q5 7 q4 7 q3 7 q 7 q 7 q0 Amod 7 Amod 7 50 6 3 mod 7 7Q A 7 7 Amod 76 mod 7 5
Recursive aroaches of calculation X (mod P) in hardware ) Recursive aroach. It is suitable for secial moduli, e.c. and X as x x x3... x x x, x,..., x X x, x,..., x X X... X X X3... n x, x,..., n 3 x,..., so X X X X... mod mod mod 3 {0, } Examle. X (mod P), where and X437 000 P 3 7 a) 000 0 0 0 mod7 000 mod 7 b) 00 00 mod 7 0 mod 7 3 mod 7 6
Recursive aroaches of calculation X (mod P) in hardware 3) It is suitable for an arbitrary modulo and is based on the next formula: X x X 0 0 3 x x x3 x4... mod P 3 x mod P x mod P x mod P x mod P... Examle. X (mod P), where 0 and 9x If If 3 X x, x,..., x P3 4 x, x, x3, x4,... {0,} 0 3 4 5 6 7 8 9 x x x3 x4 x5 x6 x7 x8 x9 x0 mod3 mod3 xmod34 x3mod38 x4mod36x5 mod3 mod38x mod33x mod33 x mod36 x mod3 6 0S3 3 Let s 7 X mod X mod X P 3S46 X 3 8 If If 9 0 mod 3 X P mod 3 X P 46S69 X 69S9 X 3 mod 3 X 030 (mod 3) 7
^n (mod P) calculation in hardware 4) X (mod P), where n P n n x, x,..., x, x,..., x mod X mod n n n x x,..., x mod n, n x, x, x3, x4,... {0,} X 000 000 0 P6 Examle. X (mod P), where and X 000 000 0mod 6 0 4 8
Exercises Using one of the considered techniques, calculate: ) 65536 (mod 3 ) 0? ) 65536 (mod 3 )? 3) (000000000) (mod 3 )? (000000000) (mod )? 4) with technique 3) 3
Arithmetic calculations in RNS Arithmetic calculations on moduli A A Converter of A A g summator/multilier (mod ) S Converter of A ositional numbers to A A A g summator/multilier (mod ) S modular reresentation to S A g modular reresentation () A A summator/multilier (mod m ) S m ositional number () A g 0
Arithmetic calculations in RNS Standard aroach of arithmetic calculations in RNS includes ) arithmetic calculations (A B=R, A+B=S, and etc., where A and B vary from 0 to P-); ) modulus function calculation (R (mod P), S (mod P), and etc.) Examle. A B=R (mod 7), hence A and B vary from 0 to 6. Lets A=5 and B=6. ) ) 56 30 0 30 (mod (00) 7) (0) ((0) (0)) (mod ((00) (00)) (mod 7) (mod 0 (mod 7) 7) 7) (mod (00)(mod 7) 7)
Arithmetic calculations in RNS 300 What is about P? ) A B R 600 ) R (mod 300 ) or Montgomery and a-la Montgomery multilication: Examle. (56) (mod 7) ((0) 4 (0) (mod 7) )(mod 7) (mod 7) (( 9(mod 7) (00)(mod 7) 3 (mod 7) 3 0 ) ( (mod 7) ))(mod 7) (mod 7) ( 4 )(mod 7) 0 (mod 7) ( )(mod 7)
Exercises ) How many rows and columns in the truth table of system of Boolean functions, which reresents A + B = R (mod 5)? ) How many rows and columns in the truth table of system of Boolean functions, which reresents A * B = R (mod 7)?
Backward conversion S S Y S Y... S m Y m r P A A Converter of A A g summator/multilier (mod ) S Converter of A ositional numbers to A A A g summator/multilier (mod ) S modular reresentation to S A g modular reresentation () A A summator/multilier (mod m ) S m ositional number () A g 4
S S Y S Y... Yi (mod i ) i S Y i m Y P Backward conversion i m k i r P ) multilication by a big number; ) big numbers summation; 3) comarison Examle. A B in RNS with moduli set P,, } {3,3,33} { 3 R s 6864 s 373 s3 6896 r 3736 5
Exercises Multily 9 * 03 in RNS with moduli set {, 3, 5, 6}?
Electronic Design Automation (EDA) tools Synosys executes X mod P; Xilinx (ISE, Vivado) imlementation IPblocks; LeonardoSectrum (Mentor Grahics) allows to use custom libraries; and etc. 7
Secial sets of moduli alied in RNS 8
Five moduli set A B A, B In order to calculate, where, 739 the average bit-range of 5 moduli sets is 300 bits, i.e. 300 3 45 9
Moduli set for A B, where A and B are 739 bits P = {0 09 03 009 997 99 983 977 97 967 96 953 947 94 937 99 99 9 907 887 883 88 877 863 859 857 853 84 839 89 87 83 8 8 809 797 787 773 769 76 757 75 743 739 733 79 77 79 709 70 69 683 677 673 66 659 653 647 643 64 63 65 69 67 63 607 60 599 593 587 577 57 569 563 557 547 54 59 53 5 5 509 503 499 49 487 479 467 463 46 457 449 443 439 433 43 4 49 409 40 397 389 383 379 373 367 36 359 353 349 347 343 337 33 37 33 3 307 93 89 83 8 77 7 69 63 57 5 4 39 33 9 7 3 99 97 93 9 8 79 73 69 67 63 57 5 49 39 37 3 7 3 09 07 03 0 97 89 83 79 73 7 67 6 59 53 47 43 4 37} 7 P 478 P 30
Features and roblems It is assumed, that: the main feature is the high seed rocessing (it is achieved with hundreds bits numbers); indeendence of calculation under each modulo; flexibility of layout; small ower consumtion; reliability Problems: unknown an efficient aroach of hardware realization for an arbitrary modulo P no IP-blocks and no hardware libraries for RNS system realization; slow seed converters to/from RNS for non secial sets of moduli 3
Residue Number Systems: Algorithms and Architectures Kluwer Academic Publishers, 00 RNS literature (in English) Digital arithmetic Morgan Kaufmann Publishers, 004 Residue Number Systems: Theory and Imlementation Imerial College Press, 007 Residue Number System Bookvika Publishing, 0 Finite recision number systems and arithmetic Cambridge University Press, 00 3