Computer Chess Club Archives




Subject: Re: typical nps on single cpus

Author: Dan Newman

Date: 22:53:43 02/14/00

Go up one level in this thread

On February 14, 2000 at 22:53:03, Dave Gomboc wrote:

>On February 14, 2000 at 22:18:18, Dan Newman wrote:
>>On February 14, 2000 at 15:25:24, Dave Gomboc wrote:
>>>On February 14, 2000 at 14:38:14, José de Jesús García Ruvalcaba wrote:
>>>>On February 14, 2000 at 03:16:33, Dave Gomboc wrote:
>>>>[big snip]
>>>>>How much faster do you think a switch is than using virtual dispatch?
>>>>What is a virtual dispatch?
>>>What you get if you went OO-crazy and had a piece class with descendents for
>>>pawn, knight, bishop, etc., then called a member function.
>>I've tried to go OO-crazy once or twice, but the one thing that seemed to
>>get in the way and require some really hairy solution was pawn promotion.
>>The only thing I could think of doing was to maintain a pool of extra
>>promotion pieces and perhaps overload new and delete in the piece class to
>>get the new piece from this pool.  But all that extra mechanism seemed like
>>too much...
>I'm not suggesting that going OO-crazy is a good idea (hence my name: OO-crazy
>:-).  I'm just wondering how much longer do you think a virtual dispatch would
>take than a standard switch statement.
>(Assuming there are no classes being loaded dynamically at run-time, there
>doesn't seem to be a reason that it should be any slower at all, in this
>particular case.  Do C++ compilers usually know that classes at the bottom of >an inheritance hierarchy are amenable to optimizations that would be unsafe on
>classes that are higher up?)

Well, if you put the move generator into one function (and it does no function
calls itself except those that are inlined) then you get the cost of one
function call.  But if you go the virtual function route, then you get a
call for each piece.  I suppose the virtual function mechamism will cost a
little extra too--maybe a couple of instructions.  For 16 pieces with the
switch statement version you get 1 function call overhead and 16 switch
statement overheads, but with the virtual function you get 16 virtual function
call overheads--and maybe a little bit more to keep track of where you are in
the move list...  Now I suspect that having to push and pop a bunch of registers
and call and ret from the function might cost more than checking the switch
statement argument for being out of range.  (And with that __assume(0) thing
even that goes away.)  I guess I'd have to do the experiment to find out.

Also, with one function, the compiler may find more things it can do to

Of course, since the move generator might only cost 10% of the cpu time, any
difference in performance will likely be minimal.  Maybe 1%.  But, if you
make a dozen such "improvements" that each give you 1%, then you've got 12%
and, perhaps, a hideous pile of spaghetti too :).


This page took 0.06 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.