Re: mulhisi3 problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Vít Mach-Žižka <V.Zizka@xxxxxxxxx> writes:

> I'd like to add this "mulhisi3" pattern now:
>         [(set (match_operand:SI 0 "register_operand" "=r")
> 	      (mult:SI (match_operand:HI 1 "register_operand" "%r")
> 		       (match_operand:HI 2 "register_operand"  "r")))]

That is not valid RTL.  You are doing a SImode multiplication of two
HImode values, which is meaningless.  You must write something like
   (mult:SI (sign_extend:SI (match_operand:HI ...))
            (sign_extend:SI (match_operand:HI ...)))


> When I compile (with -O0, GCC 4.3.2), for example, this:
> void foo()
> {
>   int a,b;    /* int size is 16bit */
>   long int c; /* long int size is 32bit - bits, bytes and word are big endian */
>
>   a = 6535;
>   b = 535;
>   c = a * b;
> }

According to the rules of C, this is doing a 16-bit multiplication,
and then sign extending the 16-bit result to assign it to a 32-bit
variable.  If you want to produce a 32-bit result, you must write
something like
    c = (long) a * (long) b;

Ian


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux