stellar

UCI Chess engine written in C++20
git clone git://git.dimitrijedobrota.com/stellar.git
Log | Files | Refs | README | LICENSE

commit 2d0ab1b27672f89ac0096924217704544c4a8901
parent 9ee804501d5cd5fd02da68ec89e975d29876e389
author Dimitrije Dobrota <mail@dimitrijedobrota.com>
date Mon, 11 Mar 2024 14:10:24 +0000

User bit header for standard functions

Diffstat:
M CMakeLists.txt | + -
M src/utils/bit.hpp | +++ --------------------

2 files changed, 4 insertions(+), 21 deletions(-)


diff --git a/ CMakeLists.txt b/ CMakeLists.txt

@@ -3,7 +3,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) project( Stellar
VERSION 1.2.1
VERSION 1.2.2
DESCRIPTION "Chess engine written in C++" HOMEPAGE_URL https://git.dimitrijedobrota.com/stellar.git LANGUAGES CXX

diff --git a/ src/utils/bit.hpp b/ src/utils/bit.hpp

@@ -2,6 +2,7 @@ #define STELLAR_BIT_H #include "utils.hpp"
#include <bit>
namespace bit {

@@ -9,26 +10,8 @@ inline constexpr bool get(const U64 &bitboard, uint8_t square) { return (bitboar inline constexpr void set(U64 &bitboard, uint8_t square) { bitboard |= (C64(1) << square); } inline constexpr void pop(U64 &bitboard, uint8_t square) { bitboard &= ~(C64(1) << (square)); }
inline constexpr uint8_t count(U64 bitboard) {
#if __has_builtin(__builtin_popcountll)
return __builtin_popcountll(bitboard);
#else
int count = 0;
for (; bitboard > 0; bitboard &= bitboard - 1)
count++;
return count;
#endif
}
inline constexpr uint8_t lsb_index(U64 bitboard) {
#if __has_builtin(__builtin_ffsll)
return __builtin_ffsll(bitboard) - 1;
#else
if (!bitboard) return -1;
return bit_count((bitboard & -bitboard) - 1);
#endif
}
inline constexpr uint8_t count(U64 bitboard) { return std::popcount(bitboard); }
inline constexpr uint8_t lsb_index(U64 bitboard) { return std::countr_zero(bitboard); }
inline constexpr U64 &lsb_pop(U64 &bitboard) { return bitboard &= bitboard & (bitboard - 1); } #define bitboard_for_each_bit(var, bb) \