Copied??? Be authentic and reinvent the wheel.Chessnut1071 wrote: ↑Thu May 12, 2022 8:03 pm I copied Pradyumna Kanna's rook & bishop magic numbers along with his shift tables and masks. The problem I'm having is ..
Magic Numbers ?
Moderator: Ras
-
- Posts: 7251
- Joined: Mon May 27, 2013 10:31 am
Re: Magic Numbers ?
-
- Posts: 313
- Joined: Tue Aug 03, 2021 2:41 pm
- Full name: Bill Beame
Re: Magic Numbers ?
it turned out his shift tables were wrong for the bishop.Henk wrote: ↑Sat May 14, 2022 2:36 pmCopied??? Be authentic and reinvent the wheel.Chessnut1071 wrote: ↑Thu May 12, 2022 8:03 pm I copied Pradyumna Kanna's rook & bishop magic numbers along with his shift tables and masks. The problem I'm having is ..
-
- Posts: 313
- Joined: Tue Aug 03, 2021 2:41 pm
- Full name: Bill Beame
Re: Magic Numbers ?
Chessnut1071 wrote: ↑Sat May 14, 2022 2:31 pmMoreover the move generation of sliding pieces is just a tiny part of the performance of a chess engine, even on an engine as simple as Dumb. Having an algo just fast enough is usually fine.abulmo2 wrote: ↑Fri May 13, 2022 6:16 pmWell, a virtual function is usually slower than a direct function. Having the right bench is also a hard task. For example, in Dumb, I tried magic numbers instead of hyperbola quintessence. Magic algo was faster in perft but slower in normal search, so a right bench would be to do a normal search on various positions covering opening, midgame and endgame, which is rather slow, and not a quick perft. And if you want to test a dozen algo this can take some time at startup.dangi12012 wrote: ↑Fri May 13, 2022 2:24 pm For perfect performance one can do a quick bench at startup and set a virt function to the fastest impl.
Moreover the move generation of sliding pieces is just a tiny part of the performance of a chess engine, even on an engine as simple as Dumb. Having an algo just fast enough is usually fine.
I just finished my magic bitboard program from classic bitboards and the performance gain was disappointing. My classic bitboard program could compute 454,545 pseudo moves per second versus the magic bitboard speed of 515,729.
Woops. correction: magic bitboards averaging 2,638,533 pseudo moves per second versus 454,545 from standard bitboards. I had some debug statements still active that need to commented out. That's about what I expected. The question I have now is about faster solutions than magic bitboards. Are they really that much faster to make a significant difference. I had a heck of a time getting magic bitboards to work. Some of the alternatives listed here are making my head ache. -- computer chip I7, 2.6 Ghz, 1 core.
-
- Posts: 1062
- Joined: Tue Apr 28, 2020 10:03 pm
- Full name: Daniel Infuehr
Re: Magic Numbers ?
Henk - he had a specific predicate to fullfill:Henk wrote: ↑Sat May 14, 2022 2:36 pmCopied??? Be authentic and reinvent the wheel.Chessnut1071 wrote: ↑Thu May 12, 2022 8:03 pm I copied Pradyumna Kanna's rook & bishop magic numbers along with his shift tables and masks. The problem I'm having is ..
"The problem I'm having is they are not unique and multiple move boards point to the same index code"
Magic hashing does not need to point only to a solution uint64_t bitmap - but when you have no overlaps you can point to any other structure you want.
But then you would like to be able to generate non overlapping magics. So you could point to a preprepared movelist - and just point there with the list of 16bit 'moves' already sorted and inplace.
Yes it makes a huge ~(35%) difference: Just copy and paste and good PEXT solution like this one:Chessnut1071 wrote: ↑Sat May 14, 2022 11:12 pm The question I have now is about faster solutions than magic bitboards. Are they really that much faster to make a significant difference. I had a heck of a time getting magic bitboards to work. Some of the alternatives listed here are making my head ache. -- computer chip I7, 2.6 Ghz, 1 core.
https://github.com/Gigantua/Chess_Moveg ... n/Pext.hpp
This also gives you direct Xray lookup which most algos didnt bother with generating - but are very useful for detecting which pieces are pinned.
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
Daniel Inführ - Software Developer
-
- Posts: 5693
- Joined: Tue Feb 28, 2012 11:56 pm
Re: Magic Numbers ?
Pext absolutely kills performance on AMD Zen 2 and earlier. Zen 2 is still modern.
And pext on ARM? What are you talking about?
That would be terrible for performance. For good performance, the magic/pext code will have to be inlined.For perfect performance one can do a quick bench at startup and set a virt function to the fastest impl.
If you don't want to settle for magic because of some lost performance on some architectures, then you need separate binaries for different CPUs or somehow try to build "fat" binaries which combine multiple separate compiles (just like MacOS X can have binaries combining x86 and ARM builds). The latter is not impossible but I don't think there is any compiler support for it.
-
- Posts: 1062
- Joined: Tue Apr 28, 2020 10:03 pm
- Full name: Daniel Infuehr
Re: Magic Numbers ?
Its simple:syzygy wrote: ↑Sun May 15, 2022 7:31 pm If you don't want to settle for magic because of some lost performance on some architectures, then you need separate binaries for different CPUs or somehow try to build "fat" binaries which combine multiple separate compiles (just like MacOS X can have binaries combining x86 and ARM builds). The latter is not impossible but I don't think there is any compiler support for it.
Benchmark on the architectures you intend to target.
Valid point:
My idea around virtuals is horrible.
The point I am making:
Having the default assumption that magic is *always* one of the fastest and picking it by default is not valid.
Recommendation:
Modern x64 (Zen3+, SandyBride+) -> PEXT
Old x64 -> Fancy Magic
Other architectures: You need to benchmark. Easiest bechmark - https://github.com/Gigantua/Chess_Movegen
Maybe I will do an EMScripten Website - so you only need to surf to a page and instantly know how the performance distribution.
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
Daniel Inführ - Software Developer
-
- Posts: 313
- Joined: Tue Aug 03, 2021 2:41 pm
- Full name: Bill Beame
Re: Magic Numbers ?
"Yes it makes a huge ~(35%) difference: Just copy and paste and good PEXT solution like this one:"dangi12012 wrote: ↑Sun May 15, 2022 5:01 pmHenk - he had a specific predicate to fullfill:Henk wrote: ↑Sat May 14, 2022 2:36 pmCopied??? Be authentic and reinvent the wheel.Chessnut1071 wrote: ↑Thu May 12, 2022 8:03 pm I copied Pradyumna Kanna's rook & bishop magic numbers along with his shift tables and masks. The problem I'm having is ..
"The problem I'm having is they are not unique and multiple move boards point to the same index code"
Magic hashing does not need to point only to a solution uint64_t bitmap - but when you have no overlaps you can point to any other structure you want.
But then you would like to be able to generate non overlapping magics. So you could point to a preprepared movelist - and just point there with the list of 16bit 'moves' already sorted and inplace.
Yes it makes a huge ~(35%) difference: Just copy and paste and good PEXT solution like this one:Chessnut1071 wrote: ↑Sat May 14, 2022 11:12 pm The question I have now is about faster solutions than magic bitboards. Are they really that much faster to make a significant difference. I had a heck of a time getting magic bitboards to work. Some of the alternatives listed here are making my head ache. -- computer chip I7, 2.6 Ghz, 1 core.
https://github.com/Gigantua/Chess_Moveg ... n/Pext.hpp
This also gives you direct Xray lookup which most algos didnt bother with generating - but are very useful for detecting which pieces are pinned.
I'm using C# windows OS target 7.0 and can not seem to get "PDEP" - C# version of PEXT - to work. Anybody using C# 7.0 have it working?
-
- Posts: 1062
- Joined: Tue Apr 28, 2020 10:03 pm
- Full name: Daniel Infuehr
Re: Magic Numbers ?
It definitely is not PDEP - but this function here:Chessnut1071 wrote: ↑Sun May 15, 2022 8:24 pm I'm using C# windows OS target 7.0 and can not seem to get "PDEP" - C# version of PEXT - to work. Anybody using C# 7.0 have it working?
https://docs.microsoft.com/en-us/dotnet ... ew=net-6.0
Namespace: System.Runtime.Intrinsics
Available in: .NET Core 3.0, Core 3.1, 5, 6, 7
Code: Select all
Bmi2.X64.ParallelBitExtract(UInt64, UInt64)
You know... Thinking of it. I originally started programming with C# and switched to C++ out of necessity (more performance and better pay) but I quite like the language. So I might even translate my "comparison of all known lookups" to C#.
Could be a fun weekend project.
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
Daniel Inführ - Software Developer
-
- Posts: 313
- Joined: Tue Aug 03, 2021 2:41 pm
- Full name: Bill Beame
Re: Magic Numbers ?
thanks, it's working. I'm thinking about trying C++, but, it was a huge leap for me coming from visual basic. When I first joined, my pseudo move generator crept along at a robust 12,230 moves per second in release mode. Now, it's clocking 6,238,303 pseudo moves/sec in release mode. Hopefully, the PEXT will take me to a new level. I dread to think what comes next.dangi12012 wrote: ↑Sun May 15, 2022 9:13 pmIt definitely is not PDEP - but this function here:Chessnut1071 wrote: ↑Sun May 15, 2022 8:24 pm I'm using C# windows OS target 7.0 and can not seem to get "PDEP" - C# version of PEXT - to work. Anybody using C# 7.0 have it working?
https://docs.microsoft.com/en-us/dotnet ... ew=net-6.0
Namespace: System.Runtime.Intrinsics
Available in: .NET Core 3.0, Core 3.1, 5, 6, 7When you get it running - it also might interestCode: Select all
Bmi2.X64.ParallelBitExtract(UInt64, UInt64)
You know... Thinking of it. I originally started programming with C# and switched to C++ out of necessity (more performance and better pay) but I quite like the language. So I might even translate my "comparison of all known lookups" to C#.
Could be a fun weekend project.
-
- Posts: 313
- Joined: Tue Aug 03, 2021 2:41 pm
- Full name: Bill Beame
Re: Magic Numbers ?
Chessnut1071 wrote: ↑Sun May 15, 2022 10:43 pmthanks, it's working. I'm thinking about trying C++, but, it was a huge leap for me coming from visual basic. When I first joined, my pseudo move generator crept along at a robust 12,230 moves per second in release mode. Now, it's clocking 6,238,303 pseudo moves/sec in release mode. Hopefully, the PEXT will take me to a new level. I dread to think what comes next.dangi12012 wrote: ↑Sun May 15, 2022 9:13 pmIt definitely is not PDEP - but this function here:Chessnut1071 wrote: ↑Sun May 15, 2022 8:24 pm I'm using C# windows OS target 7.0 and can not seem to get "PDEP" - C# version of PEXT - to work. Anybody using C# 7.0 have it working?
https://docs.microsoft.com/en-us/dotnet ... ew=net-6.0
Namespace: System.Runtime.Intrinsics
Available in: .NET Core 3.0, Core 3.1, 5, 6, 7When you get it running - it also might interestCode: Select all
Bmi2.X64.ParallelBitExtract(UInt64, UInt64)
You know... Thinking of it. I originally started programming with C# and switched to C++ out of necessity (more performance and better pay) but I quite like the language. So I might even translate my "comparison of all known lookups" to C#.
Could be a fun weekend project.