Presentation is loading. Please wait.

Presentation is loading. Please wait.

Choosing RNS Moduli Assume we wish to represent 100,000 10 Values Standard Binary  lg 2 (100,000) 10  =  16.6096 10  =17 bits RNS(13|11|7|5|3|2), Dynamic.

Similar presentations


Presentation on theme: "Choosing RNS Moduli Assume we wish to represent 100,000 10 Values Standard Binary  lg 2 (100,000) 10  =  16.6096 10  =17 bits RNS(13|11|7|5|3|2), Dynamic."— Presentation transcript:

1 Choosing RNS Moduli Assume we wish to represent 100,000 10 Values Standard Binary  lg 2 (100,000) 10  =  16.6096 10  =17 bits RNS(13|11|7|5|3|2), Dynamic Range  M=30,030 10 –Insufficient Dynamic Range –Maximum Digit Width = 4 bits, Total = 17 bits RNS(17|13|11|7|5|3|2), Dynamic Range  M=510,510 10 – Dynamic Range 5.1 Times Too Large – Maximum Digit Width = 5 bits, Total = 22 bits Adding More Prime Moduli is Inefficient

2 Choosing RNS Moduli Remove m i =5 From RNS(17|13|11|7|5|3|2) RNS(17|13|11|7|3|2), Dynamic Range  M=102,102 10 Still Have Relatively Prime Moduli – Maximum Digit Width = 5 bits, Total = 19 bits – 1 5-bit, 2 4-bit, 1 3-bit, 1 2-bit and 1 1-bit Modulo Units Required Maximum Delay 5-bit Carry-Propagate Can Combine (3,7) and (2,13) Moduli With no Speed Penalty RNS(26|21|17|11), Dynamic Range  M=102,102 10 – Maximum Digit Width = 5 bits, Total = 19 bits – 3 5-bit and 1 4-bit Modulo Units Required

3 Relatively Prime Values Powers of Smaller Primes are Relatively Prime Example gcd(3 2,2 2 )=1 But gcd(3 2,3)=3 – Can REPLACE a Modulus With its’ Power – Try Use Sequence of SMALLEST Valued Moduli RNS(2 2 |3), Dynamic Range  M=12 10 RNS(3 2 |2 3 |7|5), Dynamic Range  M=2,520 10 RNS(11|3 2 |2 3 |7|5), Dynamic Range  M=27,720 10 RNS(13|11|3 2 |2 3 |7|5), Dynamic Range  M=360,360 10 – Maximum Digit Width = 4 bits, Total = 21 bits – Dynamic Range 3.6 times that Needed

4 Relatively Prime Values RNS(13|11|3 2 |2 3 |7|5), Dynamic Range  M=360,360 10 – Maximum Digit Width = 4 bits, Total = 21 bits – Dynamic Range 3.6 times that Needed Reduce the Above by Factor of 3 Replace 3 2 with 3 and Combine 3 and 5 to Get 15 RNS(15|13|11 |2 3 |7), Dynamic Range  M=120,120 10 – Maximum Digit Width = 4 bits, Total = 18 bits – Dynamic Range 1.2 times that Needed Using This Strategy Can Generally Find the “Best” Moduli in Terms of Speed and Representation Efficiency

5 Moduli Choice for Simple Arithmetic Unit Design Simple Units Also Lead to Speed and Cost Benefits Modulo-ADD,SUBTRACT, MULTIPLY Units Simple to Design if m i =2 ai OR 2 ai -1 Power of 2 Moduli Lead to Simple Design – Standard a-bit Binary Adder – Example: Use 16 Instead of 13 – Exception in Case of Lookup Table Implementation Power of 2 a -1 Moduli Lead to Simple Design – Standard a-bit Binary Adder with End-around Carry – Referred to as “Low-cost” Moduli

6 RNS Low-Cost Moduli Theorem: A sufficient condition for 2 a -1 and 2 b -1 to be a relatively prime pair is that a and b are relatively prime. Any List of Relatively Prime Numbers: a k-2 > a k-1 >...>a 1 >a 0 Can be Used as a BASIS of k-modulus RNS: RNS(2 ak-2 |2 ak-2 -1|...|2 a1 -1|2 a0 -1) Widest Residues (Longest Carry-chain) is a k-2 -bit Values

7 Low-Cost Moduli Example Consider the Example From Earlier X=[0,100,000] Choosing the Moduli From Smallest to Largest: RNS(2 3 | 2 3 -1| 2 2 -1)Basis:3, 2M=168 10 RNS(2 4 | 2 4 -1| 2 3 -1)Basis:4, 3M=1680 10 RNS(2 5 | 2 5 -1 | 2 3 -1| 2 2 -1)Basis:5, 3, 2M=20,832 10 RNS(2 5 | 2 5 -1 | 2 4 -1| 2 3 -1)Basis:5, 4, 3M=104,160 10 Can’t Include 2 and 4 in Same Basis Set, gcd(2,4)=2

8 Low-Cost Moduli Example RNS(2 5 | 2 5 -1 | 2 4 -1| 2 3 -1)Basis:5, 4, 3M=104,160 10 = RNS(32 | 31 | 15| 7) Requires 5+5+4+3=17 bits Requires 2 5-bit, 1 4-bit and 1 3-bit Module 4 RNS Digits Efficiency = (100,001/104,160)=0.96004  100% Comparing With Unrestricted Moduli: RNS(2 5 | 2 5 -1 | 2 4 -1| 2 3 -1)17 bits M=104,160 10 5-bit Carry-ripple but Simpler Circuit, Fewer Digits RNS( 15|13|11 |2 3 |7 )18 bits M=120,120 10 4-bit Carry-ripple, 1 Extra Digit

9 Encoding and Decoding Advantages of Alternative Number Systems Must Not be Outweighed By Conversions to/from the System Encoding From Fixed Positional System to RNS Easily Accomplished Using a Table-Lookup and Modulo Addition Circuits

10 Encoding with Lookup Table Conversion of Signed-Magnitude or 2’s Complement Accomplished by Converting Magnitude and Taking RNS Complement Consider the Following Identity: Idea is to Compute a Table of All Terms and Store in a Table for all i, j Then Add

11 Example Lookup Table Use Default RNS=(8|7|5|3) For m i =8 We Can Use 3 LSbs of Value

12 Example Encoding

13 RNS to Mixed Radix Form CRT States That a Mixed-Radix Number System (MRS) is Associated with any RNS MRS is k-digit Weighted Positional Number System (m k-1 |m k-2 |...|m 2 |m 1 |m 0 ) MRS Weights are Products: (m k-2...m 2 m 1 m 0,...,m 2 m 1 m 0, m 1 m 0, m 0,1) MRS Digit Sets in Each of k Positions: [0,m k-1 -1],...,[0,m 2 -1],[0,m 1 -1],[m 0 -1] MRS Digits in Same Range as RNS Digits

14 RNS to MRS Example Example Position Weights MRS (8|7|5|3) (7)(5)(3)=105, (5)(3)=15, 3, 1 (0|3|1|0) MRS(8|7|5|3) =(0)(105)+(3)(15)+(1)(3)+(0)(1)=48 10 RNS to MRS Conversion Requires Finding the z i that Correspond to the y i in:

15 RNS to MRS Conversion From MRS Definition we Have: Easy to See that z 0 = y 0, Subtracting This Value From RNS and MRS Values Results in:

16 RNS to MRS Conversion (cont) Thus, if We Can Divide by m 0, We Have an Iterative Approach for Conversion Dividing y' (a Multiple of m 0 ) by m 0 is SCALING Easier Than Normal RNS Division Accomplished by Multiplying by Muliplicative Inverse of m 0 Next, Divide Both Representations by m 0 :

17 Multiplicative Inverses Multiplicative Inverse is a Value When Multiplied by Given Quantity Yields a Product of 1 Example Multiplicative Inverses of 3 Relative to m i =8, 7, 5: Thus, Multiplicative Inverses are 3, 5 and 2 Can Build a Lookup Table Circuit to Store Inverses

18 CRT LUT

19 Multiplicative Inverses Example Divide the Number Y' = (0|6|3|0) RNS by 3 Accomplish Through Multiplication by (3|5|2|-) RNS

20 RNS/MRS Conversion Example Convert Y=(0|6|3|0) RNS to MRS z 0 =y 0 =0 Divide by 3 Now, We Have z 1 =1, Subtract by 1 and Divide by 5

21 RNS/MRS Conversion Consider Conversion of (3|2|4|2) RNS from RNS(8|7|5|3) to Decimal Need to Determine Values of (1|0|0|0) RNS, (0|1|0|0) RNS, (0|0|1|0) RNS and (0|0|0|1) RNS

22 RNS/MRS Conversion From Definition of RNS, Positions with 0 are Multiples of RNS(8|7|5|3) and Position with 1 are m i =1

23 Chinese Remainder Theorem How Did We Find w 3 = (1|0|0|0) RNS = 105? Since Digits in 7, 5, 3 Places are 0, w 3 Must be a Multiple of (7)(5)(3)=105 Must Pick the Multiple of 105 Such That its Residue With Respect to 8 is 1 Accomplished by Multiplying 105 by its’ Multiplicative Inverse with Respect to 8 This Process is Formalized in Chinese Remainder Theorem

24 Chinese Remainder Theorem THEOREM: Chinese Remainder Theorem (CRT) The magnitude of an RNS number can be obtained from the CRT formula: where, by definition, M i = M/m i and  I = mi is the multiplicative inverse of M i with respect to m i.

25 Chinese Remainder Theorem Can Avoid Multiplications in Conversion Process by Storing mi > M in a Table Example Table Given on page 64 of Textbook


Download ppt "Choosing RNS Moduli Assume we wish to represent 100,000 10 Values Standard Binary  lg 2 (100,000) 10  =  16.6096 10  =17 bits RNS(13|11|7|5|3|2), Dynamic."

Similar presentations


Ads by Google