This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Giving hints to the compiler/optimizer (#pragma hint ...)
- From: "U.Mutlu" <um at mutluit dot com>
- To: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 22 Jun 2018 14:02:03 +0200
- Subject: Re: Giving hints to the compiler/optimizer (#pragma hint ...)
- References: <5B2C97EA.7050001@mutluit.com> <CAH6eHdSPJXDPB0QwMWZfxy0_0Sk+2eH_oc0Tz60iMSA3d08=Lg@mail.gmail.com> <5B2CD0E9.8040509@mutluit.com> <CAH6eHdQvSNdHQg9Yjk8ciacjHD88fNZgycC=uQ1nJh6tjuLVgQ@mail.gmail.com>
Jonathan Wakely wrote on 06/22/2018 01:27 PM:
On Fri, 22 Jun 2018 at 11:35, U.Mutlu wrote:
Jonathan Wakely wrote on 06/22/2018 11:42 AM:
On Fri, 22 Jun 2018 at 07:32, U.Mutlu wrote:
(The manual version has of course the disadvantage that user has to define an
additional variable and because of that, put the code in its own scope...)
You don't have to change the scope:
for (size_t i = 1, vec_sz = vec.size(); i < vec_sz; ++i)
Yes, I know that, but it lacks the "const" attribute.
Does it matter? The compiler can still see it doesn't change.
Yes, true, compiler can optimize it.
Here's another, more general C++ solution for defining any type of variables,
also additional variables to be used only inside the for-loop:
struct forVars { const size_t sz; size_t i; forVars(const size_t Asz, const
size_t Astart = 0) noexcept : sz(Asz), i(Astart) {} };
for (forVars S(vec.size()); S.i < S.sz; ++S.i) // S.sz is const
...
:-)
Maybe a little bit overkill for this simple example... :-)