This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: 64 bit assignment on a 32 bit platform
- From: Rask Ingemann Lambertsen <rask at sygehus dot dk>
- To: kum <a dot kumaresh at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 29 Oct 2007 11:40:45 +0100
- Subject: Re: 64 bit assignment on a 32 bit platform
- References: <302c6e640710290307u3750341p8c5acaaaa3fe0323@mail.gmail.com>
On Mon, Oct 29, 2007 at 03:37:04PM +0530, kum wrote:
> Hi,
>
> UINT64 a64; // UINT64 has been typedefed as long long unsigned int
> UINT32 a32, b32;
> a32 = x; // some value
> b32 = y; // some value
>
> a64 = a32 * b32;
> a64 += a32 + b32;
>
> Is it necessary to type-cast both a32 and b32 to yield correct 64 bit
> results?
"a64 = a32 * b32" multiplies two 32-bit numbers to give a 32-bit result,
which is then zero-extended to 64 bits. If you want an expanding
multiplication, use "a64 = (UINT64) a32 * (UINT64) b32".
> Without casting, I find that addition (even if the result
> overflows) works while the multiplication does not.
Which of the two additions are you talking about? Could you perhaps post
some assembly (-O2 -S -dp) of this code?
#include <stdint.h>
uint64_t a;
void addtest1 (uint32_t b, uint32_t c)
{
a += b + c;
}
> Is there a
> compiler option to make this work without casting? I am using gcc
> 4.1.1 on an xscale platform.
It would appear to work the way it is supposed to and I don't know of any
option to change that.
--
Rask Ingemann Lambertsen
Danish law requires addresses in e-mail to be logged and stored for a year