The Community for Technology Leaders
Subscribe
Issue No.02 - February (2011 vol.60)
pp: 165-175
Niels Möller , GNU GMP, Stockholm
Torbjörn Granlund , KTH - Royal Institute of Technology, Stockholm
ABSTRACT
This paper considers the problem of dividing a two-word integer by a single-word integer, together with a few extensions and applications. Due to lack of efficient division instructions in current processors, the division is performed as a multiplication using a precomputed single-word approximation of the reciprocal of the divisor, followed by a couple of adjustment steps. There are three common types of unsigned multiplication instructions: we define full word multiplication (umul), which produces the two-word product of two single-word integers; low multiplication (umullo), which produces only the least significant word of the product; and high multiplication (umulhi), which produces only the most significant word. We describe an algorithm that produces a quotient and remainder using one umul and one umullo. This is an improvement over earlier methods, since the new method uses cheaper multiplication operations. It turns out that we also get some additional savings from simpler adjustment conditions. The algorithm has been implemented in version 4.3 of the gmp library. When applied to the problem of dividing a large integer by a single word, the new algorithm gives a speedup of roughly 30 percent, benchmarked on amd and Intel processors in the x86_64 family.
INDEX TERMS
Computer arithmetic, multiple precision arithmetic, efficiency.
CITATION
Niels Möller, Torbjörn Granlund, "Improved Division by Invariant Integers", IEEE Transactions on Computers, vol.60, no. 2, pp. 165-175, February 2011, doi:10.1109/TC.2010.143
REFERENCES
 [1] T. Granlund and P.L. Montgomery, "Division by Invariant Integers Using Multiplication," Proc. SIGPLAN Conf. Programming Language Design and Implementation (PLDI '94), June 1994. [2] T. Granlund, "GNU Multiple Precision Arithmetic Library, Version 4.3," http:/gmplib.org/, May 2009. [3] D.E. Knuth, Seminumerical Algorithms, third ed., vol. 2. Addison-Wesley, 1998. [4] T. Granlund and N. Möller, "Division of Integers Large and Small," http://gmplib.org/tegedivision-survey.pdf , 2010. [5] T. Granlund, "Instruction Latencies and Throughput for AMD and Intel x86 Processors," http://gmplib.org/tegex86-timing. pdf, 2009.