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]

Re: memcpy() inlining and alignment


   From: Jason Thorpe <thorpej@netbsd.org>
   Date: Fri, 03 Mar 2000 17:22:06 -0800

   I'm not sure I buy that.  What you're effectively saying is:

	   There is no standard function in C that allows unaligned
	   data to be copied into an aligned buffer.

   Personally, I have never encountered a libc implementation of memcpy()
   that required data to be aligned in the way you're suggesting.

libc does not have available the type and alignment information
that the compiler does.

For example:

struct foo {
       unsigned int x;
};

int read_foo(struct foo *p)
{
	p->x;
}

Can the compiler assume that loading the p->x value via a
32-bit word load instruction is safe?  If so, why can it not
make the same assumption when inlining a call to memcpy.
How do the alignment rules for such a structure change in
the two cases?

Libc could in fact perform the same optimization, by inlining
the implementation in the strings.h header file by way of the
__align_of__ etc. compiler builtins.  In fact, if I am not
mistaken, glibc does do similar to this.

I'm not saying that any of this is legal, what I am saying is
what the compiler is doing and based upon what is making these
decisions.

Later,
David S. Miller
davem@redhat.com

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