mnm-sys / tezdhar

A fast and unbeatable chess engine written in C
GNU General Public License v3.0
3 stars 1 forks source link

Implement function to count set bits in a Bitboard #41

Closed mnm-sys closed 1 year ago

mnm-sys commented 1 year ago

Use GCC __builtin_popcountll() function, if available, to count set bits. Appropriate changes has to be made in configure scripts to detect support for __builtin_popcountll(). If support is not available, then fallback to an efficient software based implementation, like Brain Kernighan's algorithm to count set bits using (n &= n-1).

mnm-sys commented 1 year ago

Currently, this commit passes the linker flag LDFLAGS= -mpopcnt to the compiler to enable hardware support for __builtin_popcountll function. This linker option will fail on unsupported hardware. So, this needs further checks for portability before enabling this flag.