Author: Robert Hyatt
Date: 12:37:26 06/06/01
Go up one level in this thread
On June 06, 2001 at 15:13:02, Dan Newman wrote: >On June 06, 2001 at 12:00:06, Robert Hyatt wrote: > >>On June 06, 2001 at 09:38:47, Vincent Diepeveen wrote: >> >>>On June 06, 2001 at 09:33:00, martin fierz wrote: >>> >>>>On June 06, 2001 at 09:31:32, martin fierz wrote: >>>> >>>>>[snip] >>>>>> >>>>>>In this piece of crap code i see everywhere: >>>>>> >>>>>> if (side == WHITE) >>>>>> tsq = B->WhiteKnights; >>>>>> else >>>>>> tsq = B->BlackKnights; >>>>>> >>>>>>Note you can eliminate these branches, which speeds code up bigtime. >>>>>[snip] >>>>> >>>>>so, who can enlighten a dummy like me? how exactly can i eliminate >>>>>branches like this? i admit that my checkers program has some of these >>>>>too... although i mostly do it like this >>>>> >>>>>if(color==WHITE) >>>>argh... i hit tab return instead of return, ok, again: >>> >>>The logical thing to do which saves a dead slow branch is: >>> >>> tsq = globaltable[side]; >>> >> >> >>:) >> >>That replaces a "dead slow branch" with a "dead slower memory reference". >> >>some replacement. >> > >Yes, I'd rather do a little calculation than reference memory. Still, >wouldn't > > tsq = B->Knights[side]; > >tend to be a little faster than > > if( side == WHITE ) > tsq = B->WhiteKnights; > else > tsq = B->BlackKnights; > >since in both cases you have to get at "side" and one of those two bitmaps? Depends. A good compiler will probably recognize "side" as a very busy expression and try to keep it in a register if it is used frequently. Or else it will likely stick in L1 (or L2 worst-case) cache... > >Of course you might rather have all the bitmaps of a given color bunched >together to help with the caching... That is a basic optimization strategy... variables used close together in time should be close together in memory to take advantage of 32-byte line fills in cache. > >-Dan. > >> >> >> >>>Basically you can get rid of any easy branch you want to >>>even without using Pentiumpro instructions. >>> >>>Just create some tables. >> >>Tables == bandwidth. The PC has none. >> >> >> >>> >>>>if(color==WHITE) >>>> do lots of stuff >>>>else >>>> do lots of other stuff. >>>> >>>>is this still so stupid? >>>> >>>>cheers >>>> martin
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.