Author: Hristo
Date: 21:49:59 08/10/04
Go up one level in this thread
On August 10, 2004 at 16:12:01, Gerd Isenberg wrote:
>On August 10, 2004 at 13:35:39, Álvaro Begué wrote:
>
>>On August 10, 2004 at 10:08:59, Alessandro Scotti wrote:
>>
>>>On August 10, 2004 at 09:06:59, Álvaro Begué wrote:
>>>
>>>>I once made a very basic chess program with a single global board and an
>>>>identical program in which the pointer to the board had to be passed around. >The first one was about 15% faster. You can avoid the indirection using templates,
>>>>but it's a little tricky, and not much cleaner than having a global board.
>>>
>>>Hey, 15% is a lot faster! I'm using pointers right now but tonight I'll replace
>>>them with a global board and see what happens...
>>>
>>
>>Well, in a serious program I would expect much less of an effect. The program
>>were I tested it was a really fast program with a very simple evaluation
>>function. That's why the extra argument in many calls was a big performance hit.
>
>I guess you talk about x86-32 stdcall, where register pressure is huge and the
>board pointer has to be stored (pushed) and reloaded very often.
>If that overhead could be reduced, the pure access to the board array is most
>likely the same - or may even be faster due to shorter opcode - but of course
>you need this extra register.
>
>Fastcall might be an option - and it becomes default with AMD64.
>Up to four bytes shorter opcodes per access, if offset of board is >= 0x80.
>
>mov al,[board+rsi]
>versus
>mov al,[rcx+rsi]
>
>
>>
>>A colleague of mine proposed a way of getting rid of the indirection and the
>>extra argument, without forcing you to use a single board. It is a little
>>twisted, but interesting. You just make your engine a template class that gets a
>>pointer to Board in the template:
>>
>>class Board {
>> //...
>>};
>>
>>template <Board *b>
>>class Engine {
>> //...use the board *b for everything.
>>};
>>
>>Board my_board;
>>Engine<&my_board> my_engine;
>>
>>Board my_other_board;
>>Engine<&my_other_board> my_other_engine;
>>
>>This gives you performance that is as good as using a single global board, but
>>you can have more than one board. Of course this duplicates all the code
>>internally and your binary ends up being very large, but you can't get
>>everything.
>
>Really nice, pointer as actual template parameters.
>
>What about some "board-sharing" (in a multi-threading environment)?
>
>Board my_board;
>Engine<&my_board> my_engine;
>Engine<&my_board> my_other_engine;
>;-)
Then you'll need to make sure that you are guarding the board (semaphores,
mutexes, etc.)
If we presume that the two engine instances are running in separate threads then
the Board object should provide some locking mechanism.
I have noticed that a good SMP design is not directly mappable or even
comparable to single threaded execution. Sometimes you need to rip the whole
thing apart to get the performance you need. For instance switching the design
to use message passing instead of direct memory sharing.
Cheers,
Hristo
>
>Gerd
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.