This is the mail archive of the gcc@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: misaligned access


> Date: Wed, 13 Dec 2000 13:22:41 -0600
> From: Davy Durham <david.durham@wcom.com>
> To: Mike Stump <mrs@windriver.com>

> Yes, I suggested the memcpy solution to the guy who _actually_ has
> the problem (my very original posting was on his behalf)...  He that
> would be to (time) inefficient.. But smart as he is.... I couldn't
> convince him that 3 shifts and 4 load/stores for EVERY variable
> access in his program is even *MORE* inefficient...

The best way, is to write up a sample piece of code that uses memcpy
and ask him if it is slower than the non-memcpy code.  When he says it
is, and when you tell him it isn't, he can learn.  Here's some sample
code:

int i;
int j;
int k;

main1() {
  memcpy (&i, &k, 4);
}

main2() {
  char buf[4];
  memcpy (&buf[0], &k, 4);
  memcpy (&i, &buf[0], 4);
}

main3() {
  i = k;
}

Yes, I just compiled it, and on an x86, I happen to get the exact same
code in all three cases.  Disclaimer: Yes, this is a new feature of
gcc, yes, not all other compilers will do as well, yes, -O0 produces
worse code...

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