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: ptr vs ref performance??


> Date: Thu, 14 Dec 2000 16:36:13 -0800
> From: Rob Willis <rob@e-critical.com>

> It appears as if using a reference variable is faster than
> de-referencing from a pointer.

Cool!  :-)

> ptr de-ref:
>    value = *tp;

> ref access;
>    value = tr;

> Can anyone explain why this is?

It seems like you'll want to team up with someone that can run gcc -da
-S on the testcases, and analyze and report this type of stuff...  Or,
if you're feeling really adventuresome you could try your hand at it.
Usually, one can get it down to the pass in the optimizer that is
failing to do the best thing with the given rtl, and then you step
into the compiler with the debugger and find out why...

I tried the implied testcase and got exactly identical code:

long value = 0;
long test  = 5213;

long & tr( test );
long * tp = &test;

int main1() {
  value = *tp;
}

int main2() {
  value = tr;
}

When asking these sorts of questions, it is important to include a
testcase.  Not an idea for one, but a real one.

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