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


Branko Cibej wrote:
> My previous post with the template class
> example contains only loops written by the user -- but some STL containers
> (e.g., vector) have almost identical initialisation code.
> 
> Yes, the compiler could treat code in the standard library as "written by the
> compiler", but what if the user wrote her own STL-like container?
> 
> (I'm sure nobody wants a new #pragma :)
> 
> > This might also keep embedded programmers who believed the gcc manual
> > and wrote timing loops happy.
> 
> If they want _accurate_ timing loops, they should, as Tim Hollebeek pointed
> out, use asm statements. Otherwise they can always use volatile loop variables.

This is absolutely correct.  The performance of programs that use STL
facilities, and similar libraries like Blitz++, is utterly dependent on 
the compiler crushing out "abstraction overhead", which often means 
empty loops.  

It is impossible in general for the programmer to ensure that empty loops 
are not generated, because with templates there is no one place in the source
where all such knowledge is available.

Perhaps in C code such loops cannot be eliminated without some political
wrangling, but there can be no such excuse for g++. 

Nathan Myers
ncm@cygnus.com


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