gnugo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnugo-devel] micro-optimization


From: Gunnar Farneback
Subject: [gnugo-devel] micro-optimization
Date: Mon, 13 Jan 2003 21:31:50 +0100
User-agent: EMH/1.14.1 SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.3 Emacs/20.7 (sparc-sun-solaris2.7) (with unibyte mode)

The patch doc_3_15.1 which went into 3.3.15 among other things
includes this new comment:

> diff -u -r1.100 dragon.c
> --- engine/dragon.c   12 Jan 2003 03:49:21 -0000      1.100
> +++ engine/dragon.c   12 Jan 2003 19:26:37 -0000
> @@ -320,6 +320,7 @@
>         gprintf ("surrounded dragon found at %1m\n", dragon2[d].origin);
>      }
>      else if (dragon2[d].surround_status == WEAKLY_SURROUNDED) {
> +      /* divide by 2 */
>        dragon2[d].escape_route >>= 1;
>        if (debug & DEBUG_DRAGONS)
>         gprintf ("weakly surrounded dragon found at %1m\n", 
> dragon2[d].origin);

The normal way to write a division by two, which doesn't require a
comment, is

  dragon2[d].escape_route /= 2;

I don't know why the shift operation is used here but I can only
assume it's intended to be some kind of optimization. Please refrain
from that unless you know that

(1) The compiler needs help with the optimization.
and
(2) The code is time critical.

In this case I very much doubt that (1) is satisfied and I'm certain
that (2) isn't.

/Gunnar




reply via email to

[Prev in Thread] Current Thread [Next in Thread]