I don't really WANT to learn C. Far from it. But I am curious if a one to one translation would make an improvement in speed or do you need to use C tricks to improve the compiled code.
Is there anyone out there would like to do the conversion
Speed up your engine Part 3
Moderators: hgm, Rebel, chrisw
-
- Posts: 12540
- Joined: Wed Mar 08, 2006 8:57 pm
- Location: Redmond, WA USA
Re: Speed up your engine Part 3
Free Pascal is pretty close to C in speed.
Booot and Delfi along with some versions of Critter were written in Pascal and they are quite strong.
All three of these programs have source code available.
You can do bitboards in Pascal just as easily as C. The latest versions of 64 bit free pascal have all the important bit operation intrinsics.
If you are fluent in Pascal, I would leave the engine in Pascal unless you have a goal to learn the C programming language.
The other advantage to using C is that all the samples in the chess programming Wiki are either in C or C++.
Booot and Delfi along with some versions of Critter were written in Pascal and they are quite strong.
All three of these programs have source code available.
You can do bitboards in Pascal just as easily as C. The latest versions of 64 bit free pascal have all the important bit operation intrinsics.
If you are fluent in Pascal, I would leave the engine in Pascal unless you have a goal to learn the C programming language.
The other advantage to using C is that all the samples in the chess programming Wiki are either in C or C++.
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
-
- Posts: 12540
- Joined: Wed Mar 08, 2006 8:57 pm
- Location: Redmond, WA USA
Re: Speed up your engine Part 3
Critter:
https://sourceforge.net/projects/critterchess/
Booot:
http://www.sdchess.ru/download_engines.htm
Delfi:
http://www.msbsoftware.it/delfi/source.htm
The easiest one to learn from is probably Critter, with Delfi second.
Booot is the strongest one, but it has all of its comments in Russian so you have to translate them one by one unless you speak the language.
https://sourceforge.net/projects/critterchess/
Booot:
http://www.sdchess.ru/download_engines.htm
Delfi:
http://www.msbsoftware.it/delfi/source.htm
The easiest one to learn from is probably Critter, with Delfi second.
Booot is the strongest one, but it has all of its comments in Russian so you have to translate them one by one unless you speak the language.
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
-
- Posts: 199
- Joined: Sun Nov 03, 2013 9:32 am
Re: Speed up your engine Part 3
I have found a pascal version of tscp on the web and it does run faster than my program, so I guess the obvious conclusion is that I can improve my implementation.
I'm guessing the move gen in tscp is faster, so I will need to study whats going on.
I tried to profile my program with gprof, but got stuck and didn't go any further. Maybe I need to revisit that.
Watch this space !
I'm guessing the move gen in tscp is faster, so I will need to study whats going on.
I tried to profile my program with gprof, but got stuck and didn't go any further. Maybe I need to revisit that.
Watch this space !
-
- Posts: 179
- Joined: Fri Feb 14, 2014 10:53 pm
- Location: the Netherlands
Re: Speed up your engine Part 3
Nemeton is FreePascal.
While FPascal did not keep up with C in the optimization race it's not going to be worlds apart also simply depending on your own skill and sometimes looking at the assembler output can be a great help.
I like Pascal way more than C so when I have a choice I write in Pascal. The speedup is definitely not worth it to me and you'd have to think in the order of 10-20 Elo max.
That said learning C is pretty useful.
While FPascal did not keep up with C in the optimization race it's not going to be worlds apart also simply depending on your own skill and sometimes looking at the assembler output can be a great help.
I like Pascal way more than C so when I have a choice I write in Pascal. The speedup is definitely not worth it to me and you'd have to think in the order of 10-20 Elo max.
That said learning C is pretty useful.
-
- Posts: 199
- Joined: Sun Nov 03, 2013 9:32 am
Re: Speed up your engine Part 3
Hi,
My program uses 0x88 board. Do you think the other mailbox types have any advantage over this ?
Is Nemeton open source ?
Can I download it ?
Laurie.
My program uses 0x88 board. Do you think the other mailbox types have any advantage over this ?
Is Nemeton open source ?
Can I download it ?
Laurie.
-
- Posts: 179
- Joined: Fri Feb 14, 2014 10:53 pm
- Location: the Netherlands
Re: Speed up your engine Part 3
Yes,lauriet wrote:Hi,
My program uses 0x88 board. Do you think the other mailbox types have any advantage over this ?
Is Nemeton open source ?
Can I download it ?
Laurie.
Code: Select all
https://onedrive.live.com/redir?resid=17C791428DB77D82!636&authkey=!AOdXat1-hCCVUak&ithint=file%2crar
Nemeton uses a 16x12 mailbox representation similar to 10x12 in the way I do off-the-board detection but 16 so I can bitshift the index.
Nemeton is not such a serious chessprogram, mostly an effort to write an essentially fast program which I had to get out of my system..
People always bringing up bitboards.. Likely won't even make movegeneration faster. Might find some speedup in attack or SEE stuff but that's a small gain for a hellish boardrepresentation.
-
- Posts: 1334
- Joined: Sun Jul 17, 2011 11:14 am
Re: Speed up your engine Part 3
Bitboards aren't "hellish" if done right. They're also fast, and can be very elegant.Stan Arts wrote:Yes,lauriet wrote:Hi,
My program uses 0x88 board. Do you think the other mailbox types have any advantage over this ?
Is Nemeton open source ?
Can I download it ?
Laurie.I've never used 0x88 so can't say. For a first chessprogram making everything work as expected and understanding what's happening outweighs everything else.Code: Select all
https://onedrive.live.com/redir?resid=17C791428DB77D82!636&authkey=!AOdXat1-hCCVUak&ithint=file%2crar
Nemeton uses a 16x12 mailbox representation similar to 10x12 in the way I do off-the-board detection but 16 so I can bitshift the index.
Nemeton is not such a serious chessprogram, mostly an effort to write an essentially fast program which I had to get out of my system..
People always bringing up bitboards.. Likely won't even make movegeneration faster. Might find some speedup in attack or SEE stuff but that's a small gain for a hellish boardrepresentation.
How long does it take an array based program to calculate, say, a knight's mobility?
8 additions/subtractions for the vector, 8 register increments, 8 table lookups, assuming the compiler puts them in a temporary register, and 16 comparisons (8 for off board, 8 for avoiding counting own piece attack), plus 16(?) conditional branches. Assuming an incredibly optimistic RISC-style one instruction per clock, that's 56 clocks.
How long does it take a bitboard based program to calculate the same knight's mobility?
1 population count, a table lookup for the attacks for the knight square, a lookup for the friendly pieces, a NOT to get all squares which aren't friendly pieces, and an AND to get the attacks on the squares that aren't friendly pieces. Taking the same optimistic RISC chip, that's 5 instructions.
Or alternatively, the bitboard code is ~11 faster.
I'm not saying array based code is necessarily slow, if optimised well. But bitboards have a head start.
Some believe in the almighty dollar.
I believe in the almighty printf statement.
I believe in the almighty printf statement.
-
- Posts: 12540
- Joined: Wed Mar 08, 2006 8:57 pm
- Location: Redmond, WA USA
Re: Speed up your engine Part 3
Biggest advantage of bitboards is in evaluation.
Magic bitboards are pretty fast, even in move generation.
Magic bitboards are pretty fast, even in move generation.
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
-
- Posts: 27790
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Speed up your engine Part 3
That depends on how you implement it. When done incrementally the answer would be zero cycles, unless the last move happens to change it.ZirconiumX wrote:How long does it take a bitboard based program to calculate the same knight's mobility?