Re: Runaway cron task on 2.5.63/4 bk?

Denis Vlasenko
2003-03-12T12:18:08Z

On 12 March 2003 01:09, Andrew Morton wrote:
> > However, gcc is unable to do-the-right-thing and generate 32x32->64
> > multiplies, or 32x64->64 multiplies, even though those are both a
> > _lot_ faster than the full 64x64->64 case.
>
> 2.95.3 and 3.2.1 seem to do it right?
>
>
>
> long a;
> long b;
> long long c;
>
> void foo(void)
> {
> c = a * b;

(long * long) is a long
(long long = long) has to sign extend right side and do assignment

> }
>
>
>
> .file "t.c"
> .version "01.01"
> gcc2_compiled.:
> .text
> .align 4
> .globl foo
> .type foo,@function
> foo:
> pushl %ebp
> movl %esp,%ebp
> movl a,%eax
> imull b,%eax
> movl %eax,c

store low word...

> cltd

sign extend eax into edx...

> movl %edx,c+4

store sign-extended high word

In other words, you lost high 32 bits of 32x32 mul here
due to error in C code.

Proper example would be c = ((long long)a) * b;
--
vda