#include #include static uint64_t mul31by31to62(uint32_t a, uint32_t b) { uint64_t i; __asm__( "fildl %1\n\t" "fildl %2\n\t" "fmulp\n\t" "fistpll %0\n\t" : "=m" (i) : "m" (a), "m" (b) ); return i; } static uint64_t mul63by63to63(uint64_t a, uint64_t b) { uint64_t i; __asm__( "fildll %1\n\t" "fildll %2\n\t" "fmulp\n\t" "fistpll %0\n\t" : "=m" (i) : "m" (a), "m" (b) ); return i; } static void test(uint32_t a, uint32_t b) { printf("%08x * %08x = %016llx %016llx %016llx\n", a, b, (unsigned long long)((uint64_t)a * (uint64_t)b), mul31by31to62(a, b), mul63by63to63(a, b)); } int main(void) { test(0, 0); test(1, 0); test(0, 1); test(1, 1); test(0x10, 0x10); test(1000, 1000); test(0x1000, 0x1000); test(0x10000, 0xffff); test(0x10000, 0x10000); test(0x100000, 0x100000); test(1000000, 1000000); test(0x12345678, 0x78765432); test(0x12345678, 0x7fffffff); test(0x7fffffff, 0x7fffffff); test(0x80000000, 0x80000000); test(0x80000000, 0x80000001); test(0x80000000, 0xffffffff); test(1, 0x80000000); test(1, 0x80000001); test(0x12345678, 0x98765432); test(0x7fffffff, 0xffffffff); test(0xffffffff, 0xffffffff); return 0; }