Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Branchless code

Author: Ratko V Tomic

Date: 13:13:42 11/19/02

Go up one level in this thread


> Don't use if - else ;)

Actually, it often helps replacing 'if-else' with single 'if'
whenever at least one of the if/else blocks is very simple,
such as an assignement. For example:

  if (a)
    x=xa;
  else
    x=xb;

will work faster if changed to:

  x=xb;
  if (a)
    x=xa;

Additionally, you would want to pick x=xb to be the less
frequent case of the two, so that most of the time the
x=xa would execute with no jump at all.

In any case, even when x=xa and x=xb have similar frequencies,
you end up with smaller code and fewer executed jumps (the 'if-else'
form executes 1 jump every time and has two encoded jumps,
while the 'if' form on average executes a jump half the time
or less, and it has a single encoded jump).





This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.