New idea for my split index approach

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
Ras
Posts: 2696
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: New idea for my split index approach

Post by Ras »

Mike Sherwin wrote: Thu Jun 29, 2023 7:01 pmHere is the complete non PEXT code.
The code is not complete, it doesn't build. So what you are asking for is not someone with a PEXT CPU to perform a test run, but someone who converts your code snippets into actually testable code for you.
Rasmus Althoff
https://www.ct800.net
martinn
Posts: 20
Joined: Fri Mar 10, 2023 9:33 am
Full name: Martin Novák

Re: New idea for my split index approach

Post by martinn »

Mike Sherwin wrote: Thu Jun 29, 2023 2:21 am I do not have an efficient PEXT cpu. I can't afford to buy one. If I did or could I would test this method in a real world chess engine myself using C++. Are there no good guys/gals left? :shock:
Today I decided to revisited my previous attempt of split pext bishop attacks. I think that I found all bugs in my code and made it work hopefully.

I added it into my github repository: https://github.com/martinnovaak/motor/b ... n_pext.hpp.
I named the file kindergarten_pext but the name is probably not accurate since only horizontal attacks are calculated via KGSSB (the code for horizontal PEXT is commented out, you can uncommented it and try it out, but as I said I get better results with KGSSB horizontal attacks).

Code: Select all

static std::uint64_t rook_horizontal(int square, std::uint64_t occupancy) {
    return horizontal_subset[square][(occupancy >> horizontal_shift_table[square]) & 63];  // horizontal KGSSB
    //return horizontal_subset[square][_pext_u64(occupancy, horizontal_mask[square])];     // horizontal PEXT
}
New diagonal_subset and antidiagonal_subset are not compatible with KGSSB subsets (vertical_subset and horizontal_subset are compatible with KGSSB as I mentioned previously). In diagonal_subset 28 square had to be changed the other 36 squares are not changed. Antidiagonal_subset is completely different, since all values had to be reversed (multiplication with b2b7 file gave as blockers in order bcdefg but pext gives us blockers in order gfedcb).

The size of precalculated values is almost same as in KGSSB. In my implementation there was added vertical_mask[64]. So the size is now:

Code: Select all

static constexpr uint64_t Size = (64 * 64 * 4 + 64 * 3) * sizeof(std::uint64_t) + 64 * sizeof(std::uint32_t);
Which is 16608 * sizeof(std::uint64_t), whereas Daniel's PEXT is more than 107648 * sizeof(uint64_t). So the split pext should be more than 6 times more space efficient.

I haven't yet properly tested that. But from simple some simple perfts on the 6 positions from CPW it is probably by 9% faster than KGSSB (perft is 9% faster on average) and by 4% faster than KGSSB rook + Magic bishop. But more testing is needed.

I hope that my implementation is what you wanted. (hopefully it's also bug free)

Martin
Mike Sherwin
Posts: 965
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: New idea for my split index approach

Post by Mike Sherwin »

martinn wrote: Fri Jun 30, 2023 12:05 am Today I decided to revisited my previous attempt of split pext bishop attacks. I think that I found all bugs in my code and made it work hopefully.

I added it into my github repository: https://github.com/martinnovaak/motor/b ... n_pext.hpp.
Thanks again Martin. Now anyone can test it in a real-world chess engine with minimal effort.
Mike Sherwin
Posts: 965
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: New idea for my split index approach

Post by Mike Sherwin »

Broken promises.
Authors that do not understand teamwork.
No one willing to try my new BB generator in their own C/C++ engine.
All the lurkers that take,take,take and never give anything back.

I'm afraid that I have to be done with those people. Which means I have to be done with this place.

Although special thanks to Martin Novaak for being a team member and an all around good guy!

And thanks to Daniel Infuehr (sorry American keyboard) for working on all my algorithms and including them in his test platform. Another good guy.

And another special thanks for Thomas Jahn for including KGSSB as an alternative in C# engine Leorik.
JVMerlino
Posts: 1396
Joined: Wed Mar 08, 2006 10:15 pm
Location: San Francisco, California

Re: New idea for my split index approach

Post by JVMerlino »

I would have been happy to try it, but my CPU is four years old (AMD Ryzen 5). I can at least say that it only took me about 2 minutes to swap in your code, but the result was significantly slower. My perft test took 136.7 seconds with the PEXT code, whereas Pradu Kannan's magicmoves code took 50.9 seconds. :(
martinn
Posts: 20
Joined: Fri Mar 10, 2023 9:33 am
Full name: Martin Novák

Re: New idea for my split index approach

Post by martinn »

I have added SplitPext to my simple engine. I have run test of 11 000 games but strength was completely the same (SplitPext vs magic bishop + kgssb rook). But again my engine is simple. I guess you want rather someone with stronger engine to test that. But perft is slightly faster now, so I guess it is little bit faster.

I tried to add SplitPext into Daniel's ChessMovegen. Here are my results in his test platform on my pc:

Name Performance [MQueens/s] Tablesize Dependencies Template Author
Kindergarten 407.777402 16640 [130kb] imul64 no Urban Koistinen
Kindergarten Super SISSY Bitboards 434.450160 16672 [130kb] imul64 no Michael Sherwin
Magic Kindergarten 519.216191 16672 [130kb] imul64 no
Split Pext 533.571425 16608 [129kb] imul64 no Martin Novak, Michael Sherwin
Plain Magic BB 423.990514 295168 [2306kb] imul64 no Lasse Hansen
Black Magic BB - Fixed shift 491.084765 88891 [694kb] imul64 no Onno Garms and Volker Annuss
Pext constexpr 698.613485 107904 [843kb] pext_u64 yes Zach Wegner

Even in his platform results are really similar. But it still should be faster than Magic bitboards or KGSSB.

Maybe could Daniel add SplitPext and Magic Kindergarten into his repository. Here is a gist that I used for Split Pext https://gist.github.com/martinnovaak/b9 ... 1001b13fe8.

Magic kindergarten is only KGSSB Rook with Magic Bishop. Code that I used was only:

Code: Select all

static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::KGSSB::Rook(sq, occ) | Chess_Lookup::Plain::Bmagic(sq, occ);
Mike Sherwin
Posts: 965
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: New idea for my split index approach

Post by Mike Sherwin »

JVMerlino wrote: Mon Jul 03, 2023 7:31 pm I would have been happy to try it, but my CPU is four years old (AMD Ryzen 5). I can at least say that it only took me about 2 minutes to swap in your code, but the result was significantly slower. My perft test took 136.7 seconds with the PEXT code, whereas Pradu Kannan's magicmoves code took 50.9 seconds. :(
Thanks for verifying that it works. On AMD one needs a newer 5000 or 7000 series cpu. However, Intel has had efficient PEXT for a while now. But isn't the salient point that it takes "2 minutes" to swap in the code and test it?
Mike Sherwin
Posts: 965
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: New idea for my split index approach

Post by Mike Sherwin »

martinn wrote: Mon Jul 03, 2023 8:10 pm I have added SplitPext to my simple engine. I have run test of 11 000 games but strength was completely the same (SplitPext vs magic bishop + kgssb rook). But again my engine is simple. I guess you want rather someone with stronger engine to test that. But perft is slightly faster now, so I guess it is little bit faster.

I tried to add SplitPext into Daniel's ChessMovegen. Here are my results in his test platform on my pc:

Name Performance [MQueens/s] Tablesize Dependencies Template Author
Kindergarten 407.777402 16640 [130kb] imul64 no Urban Koistinen
Kindergarten Super SISSY Bitboards 434.450160 16672 [130kb] imul64 no Michael Sherwin
Magic Kindergarten 519.216191 16672 [130kb] imul64 no
Split Pext 533.571425 16608 [129kb] imul64 no Martin Novak, Michael Sherwin
Plain Magic BB 423.990514 295168 [2306kb] imul64 no Lasse Hansen
Black Magic BB - Fixed shift 491.084765 88891 [694kb] imul64 no Onno Garms and Volker Annuss
Pext constexpr 698.613485 107904 [843kb] pext_u64 yes Zach Wegner

Even in his platform results are really similar. But it still should be faster than Magic bitboards or KGSSB.

Maybe could Daniel add SplitPext and Magic Kindergarten into his repository. Here is a gist that I used for Split Pext https://gist.github.com/martinnovaak/b9 ... 1001b13fe8.

Magic kindergarten is only KGSSB Rook with Magic Bishop. Code that I used was only:

Code: Select all

static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::KGSSB::Rook(sq, occ) | Chess_Lookup::Plain::Bmagic(sq, occ);
The question that needs answered is how well it works with hash tables. It uses about 1/6th the memory of magic or regular PEXT and therefore should be relatively faster when used with hash tables.