now returning PopCount with builtin GCC extension

This commit is contained in:
rektdie committed 2024-04-06 13:29:53 +02:00
1 parent 2bf5865dc0
commit 6883266961
2 files changed
+5 -14

No files matched your search

+4 -13
View File
@@ -41,24 +41,15 @@ void Bitboard::PopBit(int square) {
} }
} }
int Bitboard::popCount() const { int Bitboard::PopCount() const {
U64 board = m_board; return __builtin_popcountll(m_board);
int count = 0;
while (board) {
board &= board - 1;
count++;
}
return count;
} }
// LS1B = least significant first bit // LS1B = least significant first bit
int Bitboard::getLS1BIndex() const { int Bitboard::getLS1BIndex() const {
if (m_board) { if (m_board) {
// count trailing bits before LS1B // count trailing bits before LS1B
return Bitboard((m_board & -m_board) - 1).popCount(); return Bitboard((m_board & -m_board) - 1).PopCount();
} }
return -1; return -1;
@@ -66,7 +57,7 @@ int Bitboard::getLS1BIndex() const {
Bitboard Bitboard::getOccupancy(int index, Bitboard attackMask) { Bitboard Bitboard::getOccupancy(int index, Bitboard attackMask) {
Bitboard occupancy; Bitboard occupancy;
int squareCount = attackMask.popCount(); int squareCount = attackMask.PopCount();
for (int count = 0; count < squareCount; count++) { for (int count = 0; count < squareCount; count++) {
int square = attackMask.getLS1BIndex(); int square = attackMask.getLS1BIndex();
+1 -1
View File
@@ -18,7 +18,7 @@ public:
void PopBit(int square); void PopBit(int square);
void PrintBoard() const; void PrintBoard() const;
int popCount() const; int PopCount() const;
int getLS1BIndex() const; int getLS1BIndex() const;
static Bitboard getOccupancy(int index, Bitboard attackMask); static Bitboard getOccupancy(int index, Bitboard attackMask);