Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: branch misprediction

Author: Robert Hyatt

Date: 11:01:15 07/15/04

Go up one level in this thread


On July 14, 2004 at 23:58:05, Eric Oldre wrote:

>On July 14, 2004 at 16:52:40, J. Wesley Cleveland wrote:
>
>>On July 14, 2004 at 15:04:45, Eric Oldre wrote:
>>
>>>On July 14, 2004 at 13:16:27, Dan Andersson wrote:
>>>
>>>> An online treasure trove for basic. and not so basic, CPU knowledge:
>>>>http://arstechnica.com/cpu/index.html
>>>>Look for (super-)pipelining and superscalar processors.
>>>>
>>>>MvH Dan Andersson
>>>
>>>Thanks Dan, that was an enlightening article for me. I've also now found this
>>>for people who may be interested.
>>>
>>>http://encyclopedia.thefreedictionary.com/Branch%20prediction
>>>
>>>However, now that i have some concept of what brach prediction means, how do you
>>>go about minimizing the effects of mis-pridictions? any particular practices to
>>>follow? ways to measure?
>>>
>>>Eric
>>
>>Go to the amd and intel web sites and look for their processor optimization
>>guides (I found the amd more useful). Then:
>>
>>1. Don't worry about it.
>>2. Don't worry about it except for the innermost loops.
>>3. Don't worry about it until you are seriously thinking about coding some
>>routines in assembler (your compiler will do a better job of optimizing unless
>>you really know what you are doing).
>
>
>
>Thanks (Dan and Westley) ,
>I suppose that is probably the best option for now (not worrying about it).
>considering how undeveloped my engine is at this point, i should probably be
>worried more about other things.
>
>the information you gave me was interesting to read, but i don't think i'm good
>enough yet to take advantage of it.
>
>Eric

The basic idea is to avoid branches when possible.

IE try this:

(assume t=0 or 1):

val = val + t*score_term;

rather than

if (t > 0) val = val + score_term;

No branch in the first.

That's the basic idea.  You can't eliminate all branches, but many (such as
those at the ends of loops) can be predicted with near 100% reliability by the
hardware.  Others require that you know what the default prediction scheme is
for the particular processor you are using, and that you then code your tests so
that that particular type of prediction algorithm will be correct more often
than not...




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.