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: Global variables are slower?



  In message <2473C7ACA21ED211854F08002BB768C40551D066@OZ>you write:
  > Good point about the optimization suggested! I was talking about the best
  > optimization, i. e. transform the program to:
  > 
  > printf("882236160\n");
  > 
  > on the i686, and appropriately on other platforms.
  > 
  > Is it correct to summarize that if there are no function calls between
  > repeated references to a non-volatile global variable, then it can be
  > optimized to work as well as a local variable. Otherwise, global variables
  > require extra instructions for access?
No, that is not a safe assumption.

For example, local variables are subject to register allocation (ie, they
can be easily held in a register).  The same is not generally true for globals,
so they often end up in memory.

jeff


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