Tim Peters <[EMAIL PROTECTED]> wrote: > > And for 32x32 -> 64, can't this simply be replaced by "(uint64_t)i * j", > > where uint64_t is as in C99? I'd hope that most compilers would > > manage to turn this into the appropriate 32x32-bit hardware multiply. > > 1. That's C99, not C89, and therefore less portable. > > 2. On platforms that support it, this is at least 64x64->64 multiplication, > potentially much more expensive than the 32x32->64 (or 31x31->62?) > flavor you /intend/ to move to. > > 3. There's no way to know exactly what compilers will do with this short of > staring at generated code.
I've relied in the past for the compiler generating a 32*32->64 bit multiply for this code #include <stdint.h> uint64_t mul(uint32_t a, uint32_t b) { return a*b; } Looking at the assembler it produces (x86) mul: pushl %ebp xorl %edx, %edx movl %esp, %ebp movl 12(%ebp), %eax imull 8(%ebp), %eax popl %ebp ret Which I'm pretty sure is a 32x32->64 bit mul (though my x86 assembler foo is weak). I think a compiler would have to be pretty stupid not to take this optimisation... But then there are some pretty stupid compilers out there! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com