[computer-go] g++ optimization

Łukasz Lew lukasz.lew at gmail.com
Wed Aug 30 04:32:52 PDT 2006


-march=pentium
gives a substantial speedup for me

-mpentium
surprisingly is not the same

-ftracer
is also a good choice for my code for g++ / gcc

Generally,
"Optimizing software in C++"
http://www.agner.org/optimize/optimizing_cpp.pdf
is a nice source of knowledge.

Form my own experience, for a good performance, use a KISS principle.
The smaller the code, the faster it runs :)

Łukasz Lew

On 8/30/06, Darren Cook <darren at dcook.org> wrote:
> Given recent optimization discussions, I thought this might be
> interesting. Though the real improvements in go come through clever
> algorithms, I still find it useful to run a profiler every now and again
> just to see what my program is actually doing.
>
> First I got a jump, for release version (of a tactical searcher test
> suite), from 6.2s to 2.4s, by seeing unexpected function calls and
> realizing asserts were not properly turned off. A Makefile fix was all
> that was needed.
>
> Next, I noticed 1.24% of program time was spent in
> "BIXSet_array_flagbrd::end()".
>
> BIXSet_array_flagbrd is an STL-like container for storing lists of board
> points, and with asserts stripped out the the end() function looks like:
>    inline const_iterator end(void) const{
>    return p;
>    }
>
> I'm compiling with -O3 so they should be inlined. [1]
>
> So I decided to try some of the GCC-only function attributes
> (http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html).
>
> I defined these:
>
>   #define INLINE __attribute__((always_inline)) __attribute__((nothrow))
>   #define PURE_INLINE const __attribute__((pure))
> __attribute__((always_inline)) __attribute__((nothrow))
>   #define CONST_INLINE const __attribute__((const))
> __attribute__((always_inline)) __attribute__((nothrow))
>
> And used them like this:
>   inline const_iterator end(void) CONST_INLINE{
>   return p;
>   }
>
> (I used macros so I can define them as blank for other compilers.)
>
> I added them to half a dozen key functions in just this class and got a
> speed increase from 2.4s to 2.1s. I.e. over 10% quicker.
>
> So, if you are using GCC/G++ it may be worth giving these function
> attributes [2] a try.
>
> Darren
>
> [1]: Physically commenting out my assert calls - I use a special assert
> library - gives the same timings as using function attributes to force
> inlining. So the asserts are somehow leaving something behind even in
> release versions, that doesn't affect run-time but prevents inlining.
>
> [2]: Be careful with __attribute__((const)) as if added to a non-const
> function it does NOT give a warning; instead it simply stops the
> function modifying anything. I.e. program behaviour changes wildly.
> Does anyone know if there is a way to have them generate warnings instead?
>
> _______________________________________________
> computer-go mailing list
> computer-go at computer-go.org
> http://www.computer-go.org/mailman/listinfo/computer-go/
>


More information about the computer-go mailing list