On Sun, Jan 16, 2022 at 4:11 PM Terry Reedy <[email protected]> wrote:
> > > https://stackoverflow.com/questions/41183935/why-does-gcc-use-multiplication-by-a-strange-number-in-implementing-integer-divi > > and > > > https://stackoverflow.com/questions/30790184/perform-integer-division-using-multiplication > > have multiple discussions of the technique for machine division > invariant (small) ints and GCC's use thereof (only suppressed with -0s?). > Yes, it's an old and well-known technique, and compilers have been using it for division by a known-at-compile-time constant for many decades. What's surprising here is the use by GCC in a situation where the divisor is *not* known at compile time - that GCC essentially guesses that a divisor of 10 is common enough to justify special-casing. There's also the libdivide library[1], which caters to situations where you have a divisor not known at compile time but you know you're going to be using it often enough to compensate for the cost of computing the magic multiplier dynamically at run time. [1] https://libdivide.com -- Mark
_______________________________________________ Python-Dev mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/PPF6TOGH6QJXGKYTYVVAQC4D3D3HT7R4/ Code of Conduct: http://python.org/psf/codeofconduct/
