Stanford EE 486 - lecture 4 - Residue Arithmetic

Unformatted text preview:

EE 486 Winter 02-03M. J. Flynn 1Computer Architecture & Arithmetic Group 1 Stanford UniversityEE 486 lecture 4: Residue ArithmeticM. J. FlynnComputer Architecture & Arithmetic Group 2 Stanford UniversityThe Chinese Remainder theorem• Given a set of relatively prime (r.p.) moduli (m1,m2,…mn) then for any x < M the set of residues {Xmod mi, i between 1and n} is unique, where M = Π mi; i range is from 1 to n.Computer Architecture & Arithmetic Group 3 Stanford UniversityResidue operations• (a op b) mod m = ((a mod m) op (b mod m)) mod m; • for ops add, subtract (with complement adjustment) and multiply• So “carry free” operation is possible where we concurrently execute i operations.• But results must not exceed MComputer Architecture & Arithmetic Group 4 Stanford UniversitySubtraction and complementation• Since residue is the least positive remainder, we use a complement representation.• As before if we define the upper range of M/2 to M as the negative numbers we can affect subtraction.• So that {[xic]}={[xi]}c= Xc• Overflow detection remains a problem, both for r > M and for negative result assuming a positive representation.Computer Architecture & Arithmetic Group 5 Stanford UniversityRNS terminology• For n moduli the ith residue is xi=X mod mi• X = [x1, x2, x3]m1,m2,m3; where the miare relatively prime, eg , 9=[4,0,1]5,3,2• Then [a] + [b] = [a + b], etc.Computer Architecture & Arithmetic Group 6 Stanford UniversityModuli selection• Considerations:– Relatively prime– Minimize maximum carry (the max modulus)– Efficiency (or capacity) of the representation in a fixed number of bits– Compatibility with binary (radix) ALUs.• Two systems:– Optimal: minimizes the maximum modulus– Binary: binary efficient representation & ALUEE 486 Winter 02-03M. J. Flynn 2Computer Architecture & Arithmetic Group 7 Stanford UniversityOptimal RNS• Goal: given M, find product of primes and prime powers to minimize (max mi) and result is equal to or greater than M.• 2x3x5 is not an optimal sequence since any power of 2 (eg, 4) must be r.p. to 3 and smaller than 5…so 4x3x5 is an optimal sequence… 4x3x5x7; 3x5x7x8; 5x7x8x9 are sample optimal sequences.• Max {mi} = α (M); the alpha function.Computer Architecture & Arithmetic Group 8 Stanford UniversityConversion into RNS• Table based, using (xiβi) as entry into a table of size β. Then sum the results mod mi, again using tables for determining the sums.Computer Architecture & Arithmetic Group 9 Stanford UniversityBinary (or Merrill) RNS• Binary ALU compatible and bit efficient• Select mods of the form 2n(largest) and others of the form 2k–1; k1= n; then select k2, etc. to be r.p. and provide capacity M.• Advantages:– Easy, use binary type ALUs with “end around”carry.– “Almost” the capacity of 2pwhere n + Σki= pComputer Architecture & Arithmetic Group 10 Stanford UniversityMerrill mods7,735113,5255Prime1273,763Prime313,515Prime7Prime3Prime factorsModulus Computer Architecture & Arithmetic Group 11 Stanford UniversitySome sample Merrill mod sets256,255,127,3128128,127,63,312532,31,15,717Moduli setBits to representComputer Architecture & Arithmetic Group 12 Stanford UniversityBinary to binary RNS conversion• X mod 2nis just the low order n bits of X• X mod 2k-1 is the sum of the k bit digits of X, again mod 2kwith r = 2k–1 set to 0• X mod 2k–1 = Σ (xiβi) mod 2k–1 but βmod 2k–1=1 since β = 2kand βi mod2k–1 =1, so (xiβi) mod 2k–1 = xiEE 486 Winter 02-03M. J. Flynn 3Computer Architecture & Arithmetic Group 13 Stanford UniversityConversion out of RNS• For each modulus, i , find withe wpns number that has an rns with 1 in the ith position and 0 elsewhere, wi=[0,0,1,0]• Then X mod M = (Σ (wixi)) mod MComputer Architecture & Arithmetic Group 14 Stanford UniversityRSN difficulties• Conversion back into binary• Compares• Overflows (r > M)• Subtractive overflows• Division Computer Architecture & Arithmetic Group 15 Stanford UniversityRNS as an arithmetic check• Residue check based on computation of k –bit check digit• A mod 2k-1 =[a] = (Σ ai) mod 2k-1 • A + B = C must correspond to [a]+[b]=[c]• Sum of the residues equal the residue of the sum.• Usually k= 3,4 or 5.Computer Architecture & Arithmetic Group 16 Stanford UniversityOptimal RNS• Basis for bounds on add and multiply• If we keep the largest modulus to a minimum then the carry propagation will also be


View Full Document

Stanford EE 486 - lecture 4 - Residue Arithmetic

Download lecture 4 - Residue Arithmetic
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view lecture 4 - Residue Arithmetic and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view lecture 4 - Residue Arithmetic 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?