This is the mail archive of the gcc-help@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: Is x[2] faster to access than a scalar variable?



  In message <37b5f040.0@192.117.192.1>you write:
  > >int foo()
  > >{
  > >  double x[3], y, q1;
  > >
  > >  x[2] = 1.234;
  > >  y = 1.234;
  > >  q1 = 7.2*x[2];
  > >  q2 = 7.2*y;
  > >}
  > >
  > >Is it faster to evaluate q1 or q2?
In general accessing a scalar will be more efficient than accessing a
structure or array reference as the compiler can hold scalars in registers
for a longer duration than an access to a member of an aggregate.
jeff


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