This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: GCC has problems with 64-bit multiplication
- From: Hans Petter Selasky <hselasky at c2i dot net>
- To: Graham Stott <graham dot stott at btinternet dot com>
- Cc: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 26 Feb 2007 15:35:06 +0100
- Subject: Re: GCC has problems with 64-bit multiplication
- References: <20070208150235.80441.qmail@web86107.mail.ird.yahoo.com>
On Thursday 08 February 2007 16:02, Graham Stott wrote:
> All,
>
> Not a bug in GCC the result is correct as you've only asked for a 32-bit
> multiply.
Hi again,
The problem was not that "mull" is used, but that "gcc 3.4.6" generates highly
un-optimized code when I for example multiply a 16-bit integer by a 64-bit
integer.
It actually generates code where three multiplications are used instead of
two. That has a speed impact.
Code:
#include <stdio.h>
#include <sys/types.h>
int main() {
int64_t temp;
int16_t x;
temp *= x;
printf("%lld\n", temp);
return 0;
}
objdump -D ./a.out
8048507: 89 4d e8 mov %ecx,0xffffffe8(%ebp)
804850a: 31 c0 xor %eax,%eax
804850c: 89 55 ec mov %edx,0xffffffec(%ebp)
804850f: f7 65 e8 mull 0xffffffe8(%ebp)
8048512: 6b 7d ec 00 imul $0x0,0xffffffec(%ebp),%edi
8048516: 89 d6 mov %edx,%esi
8048518: 89 c1 mov %eax,%ecx
804851a: 01 fe add %edi,%esi
804851c: 6b 45 e8 00 imul $0x0,0xffffffe8(%ebp),%eax
8048520: 83 e4 f0 and $0xfffffff0,%esp
8048523: 83 ec 14 sub $0x14,%esp
8048526: 8d 1c 06 lea (%esi,%eax,1),%ebx
--HPS