* 64 bit assignment on a 32 bit platform
@ 2007-10-29 10:15 kum
2007-10-29 10:16 ` Andrew Haley
2007-10-29 11:08 ` Rask Ingemann Lambertsen
0 siblings, 2 replies; 7+ messages in thread
From: kum @ 2007-10-29 10:15 UTC (permalink / raw)
To: gcc-help
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? Without casting, I find that addition (even if the result
overflows) works while the multiplication does not. Is there a
compiler option to make this work without casting? I am using gcc
4.1.1 on an xscale platform.
Thank you all,
kumaresh
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 64 bit assignment on a 32 bit platform
2007-10-29 10:15 64 bit assignment on a 32 bit platform kum
@ 2007-10-29 10:16 ` Andrew Haley
2007-10-29 10:25 ` kum
2007-10-29 11:08 ` Rask Ingemann Lambertsen
1 sibling, 1 reply; 7+ messages in thread
From: Andrew Haley @ 2007-10-29 10:16 UTC (permalink / raw)
To: kum; +Cc: gcc-help
kum writes:
> 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? Without casting, I find that addition (even if the result
> overflows) works while the multiplication does not. Is there a
> compiler option to make this work without casting? I am using gcc
> 4.1.1 on an xscale platform.
You have to cast at leat one of the operands in a binary operation to
get the widening to anything wider than int.
Andrew.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 64 bit assignment on a 32 bit platform
2007-10-29 10:16 ` Andrew Haley
@ 2007-10-29 10:25 ` kum
2007-10-29 10:39 ` Andrew Haley
0 siblings, 1 reply; 7+ messages in thread
From: kum @ 2007-10-29 10:25 UTC (permalink / raw)
To: Andrew Haley; +Cc: gcc-help
Thanks Andrew
Andrew>You have to cast at least one of the operands in a binary operation to
Andrew> get the widening to anything wider than int.
Is this true if int is 16 bits wide (i.e. 16 bit machine) and the
l-value is 32 bits wide?
Thanks,
kumaresh
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 64 bit assignment on a 32 bit platform
2007-10-29 10:25 ` kum
@ 2007-10-29 10:39 ` Andrew Haley
2007-10-29 10:40 ` kum
0 siblings, 1 reply; 7+ messages in thread
From: Andrew Haley @ 2007-10-29 10:39 UTC (permalink / raw)
To: kum; +Cc: gcc-help
kum writes:
> Thanks Andrew
>
> Andrew>You have to cast at least one of the operands in a binary operation to
> Andrew> get the widening to anything wider than int.
> Is this true if int is 16 bits wide (i.e. 16 bit machine) and the
> l-value is 32 bits wide?
It's true everywhere, all the time.
Andrew.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 64 bit assignment on a 32 bit platform
2007-10-29 10:39 ` Andrew Haley
@ 2007-10-29 10:40 ` kum
0 siblings, 0 replies; 7+ messages in thread
From: kum @ 2007-10-29 10:40 UTC (permalink / raw)
To: Andrew Haley; +Cc: gcc-help
Thanks again.
On 10/29/07, Andrew Haley <aph-gcc@littlepinkcloud.com> wrote:
> kum writes:
> > Thanks Andrew
> >
> > Andrew>You have to cast at least one of the operands in a binary operation to
> > Andrew> get the widening to anything wider than int.
>
> > Is this true if int is 16 bits wide (i.e. 16 bit machine) and the
> > l-value is 32 bits wide?
>
> It's true everywhere, all the time.
>
> Andrew.
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 64 bit assignment on a 32 bit platform
2007-10-29 10:15 64 bit assignment on a 32 bit platform kum
2007-10-29 10:16 ` Andrew Haley
@ 2007-10-29 11:08 ` Rask Ingemann Lambertsen
2007-10-29 15:40 ` kum
1 sibling, 1 reply; 7+ messages in thread
From: Rask Ingemann Lambertsen @ 2007-10-29 11:08 UTC (permalink / raw)
To: kum; +Cc: gcc-help
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 64 bit assignment on a 32 bit platform
2007-10-29 11:08 ` Rask Ingemann Lambertsen
@ 2007-10-29 15:40 ` kum
0 siblings, 0 replies; 7+ messages in thread
From: kum @ 2007-10-29 15:40 UTC (permalink / raw)
To: Rask Ingemann Lambertsen; +Cc: gcc-help
> Without casting, I find that addition (even if the result
> overflows) works while the multiplication does not.
Sorry, addition behaves the same way as multiplication. Thanks for your help.
Thanks all,
kumaresh
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-10-29 11:08 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-29 10:15 64 bit assignment on a 32 bit platform kum
2007-10-29 10:16 ` Andrew Haley
2007-10-29 10:25 ` kum
2007-10-29 10:39 ` Andrew Haley
2007-10-29 10:40 ` kum
2007-10-29 11:08 ` Rask Ingemann Lambertsen
2007-10-29 15:40 ` kum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).