On 1/16/2022 7:08 AM, Mark Dickinson wrote:

Now /that/ I certainly wasn't expecting. I don't see the same effect on macOS / Clang, whether compiling with --enable-optimizations or not; this appears to be a GCC innovation. And indeed, as Tim suggested, it turns out that there's no division instruction present in the loop for the division-by-10 case - we're doing division via multiplication by the reciprocal. In Python terms, we're computing `x // 10` as `(x * 0xcccccccccccccccd) >> 67`.

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?).

--
Terry Jan Reedy
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/PY3QL2XXHGGFGCA3M3JNQ6CULDIKO622/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to