Abstract
Integer division remains expensive on today's processors as the cost of integer multiplication declines. We present code sequences for division by arbitrary nonzero integer constants and run-time invariants using integer multiplication. The algorithms assume a two's complement architecture. Most also require that the upper half of an integer product be quickly accessible. We treat unsigned division, signed division where the quotient rounds towards zero, signed division where the quotient rounds towards -∞, and division where the result is known a priori to be exact. We give some implementation results using the C compiler GCC.
- 1 Robert Alverson. Integer division using reciprocals. In Peter Korncrup and David W. Matula, editors, Proceedzngs l Oth Symposium on Computer Arithmetzc, pages 186-190, Grenoble, France, June 1991.Google Scholar
- 2 Ehud Artzy, James A. Hinds, and Harry J. Saal. A fast division technique for constant divisors. CACM, 19(2):98-101, February 1976. Google ScholarDigital Library
- 3 Henry G. Baker. Computing A*B (mod N) efficiently in ANSI C. A CM ${GPLAN Notices, 27( 1):95-98, January 1992. Google ScholarDigital Library
- 4 H.B. Bakoglu, G.F. Grohoski, and R. K. Montoye. The IBM RISC system/6000 processor: Hardware overview. IBM Journal of Research and Development, 34(1):12-22, January 1990. Google ScholarDigital Library
- 5 Robert Bernstein. Multiplication by integer constants. Software- Practice and Experience, 16(7):641-652, July 1986. Google ScholarDigital Library
- 6 Raymond T. Boute. The Euclidean definition of the functions div and rood. ACM Transactions on Programming Languages and Systems, 14(2):127- 144, April 1992. Google ScholarDigital Library
- 7 A.P. Chang. A note on the modulo operation. $IGPLAN Notices, 20(4):19-23, April 1985. Google ScholarDigital Library
- 8 Digital Equipment Corporation. DECchip 2106~~ AA Microprocessor, Hardware Reference Manual, 1st edition, October 1992.Google Scholar
- 9 Intel Corporation, Santa Clara, CA. 386 DX Microprocessor Programmer's Reference Manual, 1990.Google Scholar
- 10 intel Corporation, Santa Clara, CA. intelJ86 Microprocessor Family Programmer's Reference Manual, 1992.Google Scholar
- 11 David H. Jacobsohn. A combinatoric division algorithm for fixed-integer divisors. IEEE Trans. Comp., C-22(6):608-610, June 1973.Google ScholarDigital Library
- 12 Gerry Kane. MIP$ RI$C Architecture. Prentice Hall, Englewood Cliffs, NJ, 1989. Google ScholarDigital Library
- 13 Donald E. Knuth. An empirical study of FOR- TRAN programs. Technical Report CS-186, Computer Science Department, Stanford University, 1970. Stanford artificial intelligence project memo AIM-137.Google Scholar
- 14 Donald E. Knuth. Semznumerical Algorzthms, volume 2 of The Art of Computer Programming. Addison-Wesley, Reading, MA, 2nd edition, 1981.Google Scholar
- 15 Shuo-Yen Robert Li. Fast constant division routines. IEEE Trans. Comp., C-34(9):866-869, September 1985. Google ScholarDigital Library
- 16 Daniel J. Magenheimer, Liz Peters, Karl Pettis, and Dan Zuras. Integer multiplication and division on the HP Precision Architecture. In Proceedings Second International Conference on Architectural Support for Programming Languages and Operating Systems (ASPLOS II). ACM, 1987. Published as SIGPLAN Notices, Volume 22, No. 10, October, 1987. Google ScholarCross Ref
- 17 MIPS Computer Systems, Inc, Sunnyvale, CA. MIPS lgdO00 Microprocessor User's Manual, 1991.Google Scholar
- 18 Motorola, Inc. MC68020 32-Bit Microprocessor User's Manual, 2nd edition, 1985. Google ScholarDigital Library
- 19 Motorola, Inc. PowerPC 601 RISC Microprocessor User's Manual, 1993.Google Scholar
- 20 SPARC International, Inc., Menlo Park, CA. The SPARC Archztecture Manual, Version 8, 1992. Google ScholarDigital Library
- 21 Richard M. Stallman. Using and Porting GCC. The Free Software Foundation, Cambridge, MA, 1993.Google Scholar
- 22 Henry Warren. Predicting Ezecution Time on the IBM RISU System/6000. IBM, 1991. Preliminary Version.Google Scholar
Index Terms
- Division by invariant integers using multiplication
Recommendations
Division by integers using multiplication: nifty assignment
Students are introduced to the concepts surrounding processor speed and computing cycles beginning in CS0 courses through assembly language and computer architecture courses and beyond. Students are encouraged to replace "expensive" operations such as ...
Division by invariant integers using multiplication
PLDI '94: Proceedings of the ACM SIGPLAN 1994 conference on Programming language design and implementationInteger division remains expensive on today's processors as the cost of integer multiplication declines. We present code sequences for division by arbitrary nonzero integer constants and run-time invariants using integer multiplication. The algorithms ...
Improved Division by Invariant Integers
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 ...
Comments