User bit header for standard functions
Diffstat:
2 files changed, 4 insertions(+), 21 deletions(-)
@@ -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
@@ -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) \