Mail Archives: djgpp/2002/09/21/10:45:04
"Carlo Bramini" <cbramix AT libero DOT it> wrote in
news:M2%i9.25731$Av4 DOT 488132 AT twister2 DOT libero DOT it:
> Hi to eveyone,
> I have a problem with DJGPP, but I'm going to think it's common with
> all i386 target versions of this compiler.
> I have two 32 bit numbers and I want to do:
>
> c = (a*b) >> 32;
<snip>
> It's quite strange, because on other platforms I got correct results.
> I tried MIPS, ARM, H8 and SH4, and it works as expected.
"as expected" is the key phrase here. i would not expect a 32 bit number
to hold 64 bits.
that said:
int main(void)
{
unsigned a;
unsigned b = 0xf0f0f0f0, c=01010101;
a = ((unsigned long long) b*c) >> 32;
return 0;
}
gcc -S i.c results in:
.file "i.c"
.section .text
.p2align 1
.globl _main
_main:
pushl %ebp
movl %esp, %ebp
subl $24, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl $-252645136, -8(%ebp)
movl $266305, -12(%ebp)
movl -12(%ebp), %eax
mull -8(%ebp)
movl %edx, %eax
movl $0, %edx
movl %eax, -4(%ebp)
movl $0, %eax
leave
ret
.ident "GCC: (GNU) 3.1"
adding optimization, and doing some tricks to avoid gcc computing the
result at compile time lead to a longer listing but still one mull.
--
A. Sinan Unur
asu1 AT c-o-r-n-e-l-l DOT edu
Remove dashes for address
Spam bait: mailto:uce AT ftc DOT gov
- Raw text -