This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: ARM memcpy on unaligned pointers and -O2
- From: Richard Earnshaw <rearnsha at arm dot com>
- To: Shaun Jackman <sjackman at pathwayconnect dot com>
- Cc: gcc-bugs at gcc dot gnu dot org, Richard dot Earnshaw at arm dot com
- Date: Thu, 13 Dec 2001 17:01:15 +0000
- Subject: Re: ARM memcpy on unaligned pointers and -O2
- Organization: ARM Ltd.
- Reply-to: Richard dot Earnshaw at arm dot com
> > No, your pointer is aligned. You declared it to be so in the declarations
> > of your functions. Having done this, the compiler can and does use this
> > knowledge to optimise the code.
> >
> > R.
>
> I recognized that afterwords and cast the arguments to memcpy()
>
> uint32
> ld32( const uint32* p)
> {
> uint32 ret;
> memcpy( &ret, (uint8*)p, sizeof( ret));
> return ret;
> }
>
> void
> str32( uint32* p, uint32 val)
> {
> memcpy( (uint8*)p, &val, sizeof( *p));
> }
>
> It seems the behaviour persists though. In fact, it has the exact same
> behaviour if I change the parameters from uint32* to void*.
No. Your pointer is still aligned, and the cast has no effect (there
already was an implicit cast in the prototype).
The only way you can make this work is to change the signatures of str32
and ld32 to take void* or char* pointers. Anything else is just lying to
the compiler about the type of pointer you are passing.
R.