Do you know a repo where fancy hash is implemented? I think the code I used is just plain magic.tcusr wrote: ↑Mon Dec 13, 2021 10:57 pmok the implementation is fine, thanks for trying!dangi12012 wrote: ↑Mon Dec 13, 2021 10:44 pm Update: constexpr didnt make kogge stone faster.
Its so slow because of the dependency chain. Modern processors like it when you can reorder the instructions without changing the results. Simple as that. A normal loop is as bad as this kogge stone algo.
Thats why we have the more advanced algorithms that can calculate this without a hard dependency chain and without any branches!
i thought kogge stone was slow because it was long, i still have a lot to learn about low level programming
btw my point was that queen_attacks is rarely used in a chess engine that uses kogge stone because it's expensive, try to run it again with only rook or bishops attacks
Faster than Fancy magic: Hypercube Slider lookup [TEASER]
Moderator: Ras
-
- Posts: 1062
- Joined: Tue Apr 28, 2020 10:03 pm
- Full name: Daniel Infuehr
Re: Faster than Fancy magic: Hypercube Slider lookup [TEASER]
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
Daniel Inführ - Software Developer
-
- Posts: 127
- Joined: Sat Aug 21, 2021 9:55 pm
- Full name: Jen
Re: Faster than Fancy magic: Hypercube Slider lookup [TEASER]
This is fancy magic using the best magic numbers found so far (taken from the wiki). It's a bit unwieldy because i just ripped it out of my engine and tried to squash it into one file, but hopefully it will work for youdangi12012 wrote: ↑Tue Dec 14, 2021 11:27 amDo you know a repo where fancy hash is implemented? I think the code I used is just plain magic.tcusr wrote: ↑Mon Dec 13, 2021 10:57 pmok the implementation is fine, thanks for trying!dangi12012 wrote: ↑Mon Dec 13, 2021 10:44 pm Update: constexpr didnt make kogge stone faster.
Its so slow because of the dependency chain. Modern processors like it when you can reorder the instructions without changing the results. Simple as that. A normal loop is as bad as this kogge stone algo.
Thats why we have the more advanced algorithms that can calculate this without a hard dependency chain and without any branches!
i thought kogge stone was slow because it was long, i still have a lot to learn about low level programming
btw my point was that queen_attacks is rarely used in a chess engine that uses kogge stone because it's expensive, try to run it again with only rook or bishops attacks

-
- Posts: 325
- Joined: Tue Aug 31, 2021 10:32 pm
- Full name: tcusr
Re: Faster than Fancy magic: Hypercube Slider lookup [TEASER]
why do you fill the tables at compile time?Mergi wrote: ↑Tue Dec 14, 2021 3:53 pmThis is fancy magic using the best magic numbers found so far (taken from the wiki). It's a bit unwieldy because i just ripped it out of my engine and tried to squash it into one file, but hopefully it will work for youdangi12012 wrote: ↑Tue Dec 14, 2021 11:27 amDo you know a repo where fancy hash is implemented? I think the code I used is just plain magic.tcusr wrote: ↑Mon Dec 13, 2021 10:57 pmok the implementation is fine, thanks for trying!dangi12012 wrote: ↑Mon Dec 13, 2021 10:44 pm Update: constexpr didnt make kogge stone faster.
Its so slow because of the dependency chain. Modern processors like it when you can reorder the instructions without changing the results. Simple as that. A normal loop is as bad as this kogge stone algo.
Thats why we have the more advanced algorithms that can calculate this without a hard dependency chain and without any branches!
i thought kogge stone was slow because it was long, i still have a lot to learn about low level programming
btw my point was that queen_attacks is rarely used in a chess engine that uses kogge stone because it's expensive, try to run it again with only rook or bishops attacks![]()
i don't see any advantage
-
- Posts: 1062
- Joined: Tue Apr 28, 2020 10:03 pm
- Full name: Daniel Infuehr
Re: Faster than Fancy magic: Hypercube Slider lookup [TEASER]
Thanks I will implement Mergi!
tcusr its best to have it at compiletime. When a compiler can infer what the value is it will instantly inline the value. So attacks[23] is a constant. Now if you have a case where you test certain squares like [62] it will make the code faster.
So in summary you lose nothing in most cases - but there are cases where you can win A LOT of performance.
Last edited by dangi12012 on Tue Dec 14, 2021 7:24 pm, edited 1 time in total.
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
Daniel Inführ - Software Developer
-
- Posts: 1062
- Joined: Tue Apr 28, 2020 10:03 pm
- Full name: Daniel Infuehr
Re: Faster than Fancy magic: Hypercube Slider lookup [TEASER]
Does not compile: Neither in clang nor in msvc.
error: call to consteval function 'Chess_Lookup::Fancy::InitTable<88064, const std::array<unsigned char, 64>, const std::array<unsigned long, 64>, unsigned long (Chess_Lookup::Fancy::Square, unsigned long)>' is not a constant expression
constexpr auto r_table = InitTable<88064>(r_magic_shift, r_magic_num, GenRookMoves);
Also too much use of auto keyword
Upate: When removing constexpr and inling manually it throws too. I need working code!

So 88064 is the current record for variable shift fancy magic?
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
Daniel Inführ - Software Developer
-
- Posts: 127
- Joined: Sat Aug 21, 2021 9:55 pm
- Full name: Jen
Re: Faster than Fancy magic: Hypercube Slider lookup [TEASER]
Hmm, i'm not sure clang has enough consteval/constexpr/auto support yet. It does compile with GCC 11 though. I'll post a non compile time code in a moment, that should work with clang as well.dangi12012 wrote: ↑Tue Dec 14, 2021 7:21 pmDoes not compile: Neither in clang nor in msvc.
error: call to consteval function 'Chess_Lookup::Fancy::InitTable<88064, const std::array<unsigned char, 64>, const std::array<unsigned long, 64>, unsigned long (Chess_Lookup::Fancy::Square, unsigned long)>' is not a constant expression
constexpr auto r_table = InitTable<88064>(r_magic_shift, r_magic_num, GenRookMoves);
Also too much use of auto keyword
Upate: When removing constexpr and inling manually it throws too. I need working code!
So 88064 is the current record for variable shift fancy magic?
-
- Posts: 127
- Joined: Sat Aug 21, 2021 9:55 pm
- Full name: Jen
Re: Faster than Fancy magic: Hypercube Slider lookup [TEASER]
No fancy autos or constexpr anymore!

-
- Posts: 127
- Joined: Sat Aug 21, 2021 9:55 pm
- Full name: Jen
Re: Faster than Fancy magic: Hypercube Slider lookup [TEASER]
No idea, i'm using the publicly available magic numbers from https://www.chessprogramming.org/Best_Magics_so_fardangi12012 wrote: ↑Tue Dec 14, 2021 7:21 pm So 88064 is the current record for variable shift fancy magic?
Unless there were some new added in the past few months or i missed some when i was originally making the generator, 88064 for rooks and 4800 for bishops should be the smallest for fancy magics.
-
- Posts: 1062
- Joined: Tue Apr 28, 2020 10:03 pm
- Full name: Daniel Infuehr
Re: Faster than Fancy magic: Hypercube Slider lookup [TEASER]
Strange this seems to be 30% slower than this implementation:
Will try different compilers...
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
Daniel Inführ - Software Developer
-
- Posts: 1062
- Joined: Tue Apr 28, 2020 10:03 pm
- Full name: Daniel Infuehr
Re: Faster than Fancy magic: Hypercube Slider lookup [TEASER]
Ah the performance is slow because:Mergi wrote: ↑Tue Dec 14, 2021 8:01 pmNo idea, i'm using the publicly available magic numbers from https://www.chessprogramming.org/Best_Magics_so_fardangi12012 wrote: ↑Tue Dec 14, 2021 7:21 pm So 88064 is the current record for variable shift fancy magic?
Unless there were some new added in the past few months or i missed some when i was originally making the generator, 88064 for rooks and 4800 for bishops should be the smallest for fancy magics.
Code: Select all
((occ & m.inner_mask) * m.magic_num) >> m.shift
Can anyone here on this forum point me to the sourcecode of a fancy magic with fixed shift implementation?
It would look like that:
Code: Select all
((occ | m.inner_mask) * m.magic_num) >> (64-12)
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
Daniel Inführ - Software Developer