This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ARM memcpy on unaligned pointers and -O2


> > 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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]