This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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: overhead of bfd_{get,put}*()


On Tuesday 23 February 2010 14:24:42 Joseph S. Myers wrote:
> If you want to do unaligned accesses, you can either access byte-by-byte
> as at present, or use memcpy to an aligned object (plus byte-swapping as
> needed) and hope the compiler optimizes that, or use packed structures
> (GCC-specific) (plus byte-swapping as needed).  Simply dereferencing an
> unaligned pointer is not safe.

i dont think that has worked for a while now.  if you have a pointer with a 
certain alignment requirement and give it to memcpy(), gcc has no problem 
inlining the memcpy() with direct loads even if the source pointer is 
unaligned.

hopefully this conveys what i'm talking about:
void foo(int *src, long *dst)
{
	memcpy(src, dst, 8);
}
...
{
	char buf[12];
	long d;
	void *s = buf + 1;
	foo(s, &d);
}

gcc has no problem assuming that src/dst are always aligned upon entry to 
foo() according to the requirements of the "long" type and inlining that 
memcpy() into two 4 byte copies.
-mike

Attachment: signature.asc
Description: This is a digitally signed message part.


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