3DSoftware.com > Programming > Integers > Page 6
Integers  Page 6
 
Wide Unsigned Integers
 
Multiplication
 
Multiplication of wide unsigned integers consists of multiplying digit packets and adding together those products.
 
 
“Polynomials have many properties similar to those of integers.”
—  Shafarevich, p. 28
Multiplying together two 32-bit numbers produces a 64-bit number. We multiply two 30-bit numbers together to produce a 60-bit number. Each 30-bit number is actually a 32-bit number with the two high bits cleared, and the product is a 64-bit number with the 4 high bits cleared.
 
Multiplying together two 64-bit numbers, A and B, produces a 128-bit number AB. To use 32-bit multiplication, each 64-bit operand (A and B) must be split into high and low 32-bit operands:
 
A1 is the high order 32 bits of A       A0 is the low order 32 bits of A
 
B1 is the high order 32 bits of B       B0 is the low order 32 bits of B
 
A and B become polynomials (with t = 232):
 
A = A1t + A0
 
B = B1t + B0
 
Multiplying polynomials together consists of multipying each term of one polynomial (one at a time) with each term of the other polynomial (one at a time) and summing those products. That sum, which is the product of multiplying two polynomials, is itself a polynomial.
 
The product of the polynomials A and B we defined above is the following polynomial AB:
 
AB = A1B1t2 + (A1B0 + A0B1)t + A0B0
 
t2 = 264, t = 232
 
The first and last terms are adjacent non-overlapping bit fields so they can be ORed together instead of added together (shifting the first term left 64 bits eliminates t²). The other terms are shifted left 32 bits to eliminate t and are then added to the result.
 
In that example, A was a 64-bit number, B was a 64-bit number, and the product AB was a 128-bit number.
 
Now we will multiply two 128-bit numbers, C and D. The product CD will be a 256-bit number. The numbers to be multiplied are the following polynomials:
 
C = A3t3 + A2t2 + A1t + A0
 
D = B3t3 + B2t2 + B1t + B0
 
t3 = 296, t2 = 264, t = 232
An are digit packets of C
Bn are digit packets of D
 
The 32-bit digit packets are indexed n=0 for the low order 32 bits (bits 31–0), n=1 for bits 63–32, etc. For example, B1 is the packet of bits 63–32 of D.
 
The product CD is a 256-bit number:
 
 CD  =   A3B3t6
+ ( A3B2 + A2B3 )t5
+ ( A3B1 + A2B2 + A1B3 )t4
+ ( A3B0 + A2B1 + A1B2 + A0B3 )t3
+ ( A2B0 + A1B1 + A0B2 )t2
+ ( A1B0 + A0B1 )t 
+ A0B0 
 
Now we will multiply two 256-bit numbers, E and F:
 
E = A7t7 + A6t6 + A5t6 + A4t4 + A3t3 + A2t2 + A1t + A0
 
F = B7t7 + B6t6 + B5t6 + B4t4 + B3t3 + B2t2 + B1t + B0
 
An are digit packets of E,   Bn are digit packets of F
 
 
The product EF is a 512-bit number:
 
 EF  =   A7B7t14
+ ( A7B6 + A6B7 )t13
+ ( A7B5 + A6B6 + A5B7 )t12
+ ( A7B4 + A6B5 + A5B6 + A4B7 )t11
+ ( A7B3 + A6B4 + A5B5 + A4B6 + A3B7 )t10
+ ( A7B2 + A6B3 + A5B4 + A4B5 + A3B6 + A2B7 )t9
+ ( A7B1 + A6B2 + A5B3 + A4B4 + A3B5 + A2B6 + A1B7 )t8
+ ( A7B0 + A6B1 + A5B2 + A4B3 + A3B4 + A2B5 + A1B6 + A0B7 )t7
+ ( A6B0 + A5B1 + A4B2 + A3B3 + A2B4 + A1B5 + A0B6 )t6
+ ( A5B0 + A4B1 + A3B2 + A2B3 + A1B4 + A0B5 )t5
+ ( A4B0 + A3B1 + A2B2 + A1B3 + A0B4 )t4
+ ( A3B0 + A2B1 + A1B2 + A0B3 )t3
+ ( A2B0 + A1B1 + A0B2 )t2
+ ( A1B0 + A0B1 )t 
+ A0B0 
 
References
 
Polynomials:
 
[Shaf]   Shafarevich, I.R., 2003, Discourses on Algebra, p. 27.  Note: In the equations for g(x) on that page, if one of the terms is b1g, that term should be b1x.
 
[Barb]   Barbeau, E.J., Polynomials, p. 2.
 
[Irving]   Irving, R.S., Integers, Polynomials, and Rings, p. 222.
 
—  Page 6  —
 « Page 5 Contents Page 7 » 
 
Copyright © 2008 by 3D Software. All rights reserved.
3D Software, P.O. Box 221190, Sacramento CA 95822 USA
www.3DSoftware.com     Contact us
Thursday, 20-Nov-2008 14:13:26 GMT