Download presentation
Presentation is loading. Please wait.
Published byMarvin Hutchinson Modified over 6 years ago
1
CSE 575 Computer Arithmetic Spring 2003 Mary Jane Irwin (www. cse. psu
CSE 575 Computer Arithmetic Spring Mary Jane Irwin (
2
RNS(8|7|5|3) gives 840 distinct values
Residue Number System Positional - value of symbol is position dependent Mixed radix - the number is represented by the residues wrt k pairwise relatively prime moduli (bases) mk-1 > … m1 > m0 (e.g., 8 > 7 > 5 > 3) Digit set - for the ith position is [0, mi -1] xi = X mod mi = (X)mi Range - number of distinct values is the product M of the k pairwise moduli RNS(8|7|5|3) gives 840 distinct values M = 8 X 7 X 5 X 3 = 840 (m3 – 0 to 7 in 3 bits, m2 – 0 to 6 in 3 bits, m1 0 to 4 in 3 bits, m1 0, 1, 2 in 2 bits = 11 bits total) And each of the moduli are relatively prime (prime wrt each other)
3
RNS Machine Representation
In practice, each residue is encoded in binary So the representational efficiency is much less than with binary 840/2048 = 41% = 11 bits mod 3 mod 7 mod 8 mod 5
4
RNS(8|7|5|3) Examples (0|0|0|0)RNS(8|7|5|3) represents 0 or 840 or …
840/8=105 with 0 remainder;840/7=120 with 0 remainder;840/5=168 with 0 remainder;840/3=280 with 0 remainder 8/8=1 with 0 remainder;8/7=1 with 1 remainder;8/5=1 with 3 remainder;8/3=2 with 2 remainder 21/8=2 with 5 remainder;21/7=3 with 0 remainder;21/5=4 with 1 remainder;21/3=7 with 0 remainder 64/8=8 with 0 remainder;64/7=9 with 1 remainder;64/5=12 with 4 remainder;64/3=21 with 1 remainder 8-2|0|0|3-2 = 6|0|0|1 = +70 where 70/8=8 with 6 remainder;70/7=10 with 0 remainder;70/5=16 with 0 remainder; 70/3=23 with 1 remainder (convert to positive rep. then convert to decimal or RNS) 8-7|7-6|5-4|3-2 = 1|1|1|1 = +1 and see above
5
Representing Negative Numbers
Since (-X)mi = (M - X)mi can shift the range from 0 to M to –M/2 to M/2 – 1 or any other interval of M consecutive integers Negative numbers are represented using a complement system with the complementation constant M Given the RNS of X, the representation of –X can be found by complementing each of the digits xi wrt its moduli mi (0 digits unchanged) So since 21 = (5|0|1|0)RNS(8|7|5|3) then –21 = (8-5|0|5-1|0)RNS = (3|0|4|0)RNS
6
RNS(5|3|2) Complement Coding
M = 5x3x2 = 30 distinct values that can be mapped to 0 to 29 or –15 to +14 000 421 111 220 310 -1 +1 -2 +2 201 301 -3 +3 increment 120 -4 +4 410 For lecture +15 = 0|0|1 so –15 = 0|0|2-1 = 0|0|1 -14 = 5-4|3-2|0 = 1|1|0 +13 = 3|1|1 so –13 = 5-3|3-1|2-1 = 2|2|1 … +5 021 … -13 221 -14 +14 -15 420 110 001 +13 = 3 | 1 | 1 -13 = 5-3 | 3-1 | 2-1 = 2 | 2 | 1
7
Residue Arithmetic Negation
Independently complementing each of the moduli digits (e.g., mi – xi) 1 = (1|1|1|1)RNS(8|7|5|3) then -1 = (8-1|7-1|5-1|3-1)RNS(8|7|5|3) = (7|6|4|2)RNS(8|7|5|3) Similarly, addition, subtraction, and multiplication are performed by independently operating on each moduli digit Since each digit is a relatively small number, digit operations are quite fast and simple in RNS Go back and look at the number wheel for insight into “increment” operation “pretty much” solves the carry propagation problem – only have to worry about the carry propagation time for the largest moduli Also consider that for multiplication the operations are MUCH simpler – a 4x4 multiplier is considerably faster and smaller than a 16x16 multiplier (more than 4 times simpler)
8
RNS Arithmetic Examples
RNS( 8 | 7 | 5 | 3 ) RNS ( 5 | 3 | 2 ) X= ( 5 | 5 | 0 | 2 ) ( | | ) Y= ( 7 | 6 | 4 | 2 ) ( | | ) X+Y= | 5+6|0+4|2+2 ( 4 | 4 | 4 | 1 ) ( | | ) X-Y= |5-6|0-4|2-2 ( 6 | 6 | 1 | 0 ) ( | | ) X*Y= *7|5*6|0*4|2*2 ( 3 | 2 | 0 | 1) ( | | ) for lecture 35 mod8 = 3 30 mod7 = 2
9
RNS ALU ops: +, -, * incr. negate mod 5 unit mod 3 unit mod 8 unit
mod logic 2 3 3 3
10
Residue Arithmetic, Con’t
Unfortunately, the complexity of division and auxiliary operations like sign test, magnitude comparison, and overflow detection can nullify gains (7|2|2|1)RNS(8|7|5|3) (2|5|0|1)RNS(8|7|5|3) which are negative?, which is larger?, does (1|0|2|2)RNS(8|7|5|3) represent their true sum as opposed to the residue of their sum modulo 840 (i.e., overflow)?
11
Selecting the Moduli All moduli must be relatively prime
powers of any two prime numbers are relatively prime Product of the moduli determines the range of the system so bigger moduli increase the range Largest module dictates the speed of arithmetic operations (worst case carry) try for moduli close to together so that all moduli positions take about the same time to do an arithmetic operation
12
Selecting the Moduli, Con’t
Moduli with powers-of-2 (mi = 2k) give the most efficient encoding into binary k bits can encode exactly 2k distinct values Arithmetic units with mi = 2k or mi = 2k - 1 are easiest to design can use simple 2s’c and 1s’c binary adders/subtractors/ multipliers don’t have to do the trailing mod operations (hardware does it automatically !)
13
Picking Good Moduli Any list of relatively prime numbers ak-2 > … a1 > a0 can be the basis of the k modulus RNS RNS(2ak-2|2ak-2-1| …| 2a1-1| 2a0-1) To maximize the dynamic range, the even modulus is chosen to be as large as possible
14
Some Good Moduli Choices
RNS(23| 23-1| 22-1) (8|7|3) M = 168; 8b RNS(24| 24-1| 23-1) (16|15|7) M = 1680; 11b RNS(25| 25-1| 23-1|22-1|) (32|31|7|3) M = 20,832; 15b RNS(25| 25-1| 24-1|23-1|) (32|31|15|7) M = 104,160; 17b RNS(26| 26-1| 25-1) (64|63|31) M = 124,992; 17b RNS(27| 27-1| 26-1|25-1|) (128|127|63|31) M = 31,747,968; 25b 3,2; 4,3; 5,3,2 and 5,4,3; 6,5; 7,6,5 and 7,5,4,3 and 7,5,3,2; 9,8,7,5 and 9,7,5,4 and 9,7,5,2; etc. Note that with 25 bits, we can almost represent as many objects as with the conventional binary system (2**25)
15
RNS(16|15|7) ALU mod 7 1s’c unit mod 16 2s’c unit mod 15 1s’c unit 4 3
Bigger range than previous 11 bit system (8|7|3|2) – 1,680 versus 840 Longer carry chain – 4 bits instead of 3 bits Fewer logic blocks (but bigger ones) – no special mod logic adjusters needed 4 3 4
16
RNS(8|7|5|3) ALU ops: +, -, * incr. negate mod 5 unit mod 3 1’sc unit
2 3 3 3 mod logic
17
RNS Conversion Conversion from binary/decimal to RNS
Given a number y, find its residues with respect to the moduli mi, 0 i k-1 Can use some table lookup short cuts to avoid the divisions Conversion from RNS to binary/decimal Makes use of the Chinese remainder theorem
18
RNS Suitable Applications
ASIC parts that don’t have to conform to the floating point standard 1,000’s of operations after input conversion before output conversion is necessary Never have to do sign detect, overflow detect, comparison, division Some signal processing operations (e.g., filters)
19
Key References Garner, The Residue Number System, IRE Trans. Electronic Computers, Vol. 8, pp , June 1959. Jenkins, Finite Arithmetic Concepts, in Handbook for Digital Signal Processing, pp , Wiley, 1993. Parhami, Computer Arithmetic, Oxford Univ. Press, 1999. Soderstrand, Jenkins, Jullien, Taylor, Residue Number System Arithmetic, IEEE Press, 1986. Szabo, Tanaka, Residue Arithmetic and Its Applications to Computer Technology, McGraw-Hill, 1967.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.