Optimizing Bishop, Rook, and Queen Move Generation in a Chess Engine
summary
Claim: sliding-piece generation drops from ~20+ ns to ~1 ns by using magic bitboards implemented in software as a portable alternative to PEXT. Implementation lives in FollyChess, with build-time table generation wired into Bazel because consteval RNGs fail. Microbenchmarks show bishops ~1.23 ns, rooks ~1.30 ns, queens ~1.96 ns; finding magic constants takes many random attempts but the generator runs in ~1 s during build. End-to-end search sees ~1.2–1.3× speedups and stable ~2.5M nodes/sec on test positions.
AI-written summary · about
chapters (9)
- 0:00Introduction
- 4:29Chess engine data structures
- 15:50Knight moves with bitboards
- 20:01Sliding pieces basics
- 26:28Bishop rook queen challenges
- 44:02Fast sliding piece generation
- 59:22Magic bitboards
- 1:18:09Performance benchmarks
- 1:32:16Q&A
related talks
56mWrite Fast Code Like a Native
01h 00m“When a Microsecond Is an Eternity: High Performance Trading Systems in C++”
05mOptimizing C++ Builds - Lessons from Elden Ring for Software Engineering
34mFast Code Without Breaking Things
01h 00mFastware
23mBeating the Benchmarks: Co-evolving the ISA and Development Tools
19mHow NOT To Program an Out-of-order Vector Processor
01h 50mUnlocking Modern CPU Power - Next-Gen C++ Optimization Techniques
