From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: Problem with multiplications Date: 21 Sep 2002 14:33:28 GMT Organization: Cornell University Lines: 61 Sender: asu1 AT cornell DOT invalid (on pool-141-149-206-58.syr.east.verizon.net) Message-ID: References: NNTP-Posting-Host: pool-141-149-206-58.syr.east.verizon.net X-Trace: news01.cit.cornell.edu 1032618808 29764 141.149.206.58 (21 Sep 2002 14:33:28 GMT) X-Complaints-To: usenet AT news01 DOT cit DOT cornell DOT edu NNTP-Posting-Date: 21 Sep 2002 14:33:28 GMT User-Agent: Xnews/5.04.25 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "Carlo Bramini" 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; > 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