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: Loop unrolling


Martin Knoblauch writes:
 > > 	{
 > > 	  volatile int i;
 > > 	  for (i = 0; i < 10000; ++i);
 > > 	}
 > >
 > 
 >  Hmm. Does this prevent the loop from being deleted,
 > or would it allow the compiler to just assign
 > 9999 to "i"?

It should prevent the loop from being deleted.  My memory
of the standard is vague, but basically, "volatile" tells
the compiler that it actually must read and write the 
memory location.  The compiler must assume that writing
to the memory location has some unseen effect (say the
memory location actually some device register),  and
also that the memory locations value might change in
an unseen way from the write to the following read.

This isn't the actuall wording, but it's something like:
If the expressions between two sequence points contain
one or more stores to a volatile memory location, then the
running program must make at least one store to that
memory location (storing the proper value).  Similarly
for reads from a volatile memory location.


                              -gavin...


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