We don't need different names between a function and a
template. Compiler will know when use one or the other.
This let use restore original count_1s_xx() names instead of
sw_count_1s_xxx so to simplify a bit the code.
No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
Bitboard index_to_bitboard(int index, Bitboard mask) {
Bitboard index_to_bitboard(int index, Bitboard mask) {
- int i, j, bits = count_1s<false>(mask);
+ int i, j, bits = count_1s(mask);
Bitboard result = 0ULL;
for(i = 0; i < bits; i++) {
j = pop_1st_bit(&mask);
Bitboard result = 0ULL;
for(i = 0; i < bits; i++) {
j = pop_1st_bit(&mask);
inline bool cpu_has_popcnt() { return false; }
inline bool cpu_has_popcnt() { return false; }
-#define POPCNT_INTRINSIC(x) sw_count_1s(x)
-#define BITSCAN_INTRINSIC(idx, x) sw_count_1s(x) // dummy
+#define POPCNT_INTRINSIC(x) count_1s(x)
+#define BITSCAN_INTRINSIC(idx, x) count_1s(x) // dummy
#if defined(BITCOUNT_LOOP)
#if defined(BITCOUNT_LOOP)
-inline int sw_count_1s(Bitboard b) {
+inline int count_1s(Bitboard b) {
int r;
for(r = 0; b; r++, b &= b - 1);
return r;
}
int r;
for(r = 0; b; r++, b &= b - 1);
return r;
}
-inline int sw_count_1s_max_15(Bitboard b) {
+inline int count_1s_max_15(Bitboard b) {
return count_1s(b);
}
#elif defined(BITCOUNT_SWAR_32)
return count_1s(b);
}
#elif defined(BITCOUNT_SWAR_32)
-inline int sw_count_1s(Bitboard b) {
+inline int count_1s(Bitboard b) {
unsigned w = unsigned(b >> 32), v = unsigned(b);
v -= (v >> 1) & 0x55555555; // 0-2 in 2 bits
w -= (w >> 1) & 0x55555555;
unsigned w = unsigned(b >> 32), v = unsigned(b);
v -= (v >> 1) & 0x55555555; // 0-2 in 2 bits
w -= (w >> 1) & 0x55555555;
-inline int sw_count_1s_max_15(Bitboard b) {
+inline int count_1s_max_15(Bitboard b) {
unsigned w = unsigned(b >> 32), v = unsigned(b);
v -= (v >> 1) & 0x55555555; // 0-2 in 2 bits
w -= (w >> 1) & 0x55555555;
unsigned w = unsigned(b >> 32), v = unsigned(b);
v -= (v >> 1) & 0x55555555; // 0-2 in 2 bits
w -= (w >> 1) & 0x55555555;
#elif defined(BITCOUNT_SWAR_64)
#elif defined(BITCOUNT_SWAR_64)
-inline int sw_count_1s(Bitboard b) {
+inline int count_1s(Bitboard b) {
b -= ((b>>1) & 0x5555555555555555ULL);
b = ((b>>2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
b = ((b>>4) + b) & 0x0F0F0F0F0F0F0F0FULL;
b -= ((b>>1) & 0x5555555555555555ULL);
b = ((b>>2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
b = ((b>>4) + b) & 0x0F0F0F0F0F0F0F0FULL;
-inline int sw_count_1s_max_15(Bitboard b) {
+inline int count_1s_max_15(Bitboard b) {
b -= (b>>1) & 0x5555555555555555ULL;
b = ((b>>2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
b *= 0x1111111111111111ULL;
b -= (b>>1) & 0x5555555555555555ULL;
b = ((b>>2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
b *= 0x1111111111111111ULL;
template<bool UseIntrinsic>
inline int count_1s(Bitboard b) {
template<bool UseIntrinsic>
inline int count_1s(Bitboard b) {
- return UseIntrinsic ? POPCNT_INTRINSIC(b) : sw_count_1s(b);
+ return UseIntrinsic ? POPCNT_INTRINSIC(b) : count_1s(b);
}
template<bool UseIntrinsic>
inline int count_1s_max_15(Bitboard b) {
}
template<bool UseIntrinsic>
inline int count_1s_max_15(Bitboard b) {
- return UseIntrinsic ? POPCNT_INTRINSIC(b) : sw_count_1s_max_15(b);
+ return UseIntrinsic ? POPCNT_INTRINSIC(b) : count_1s_max_15(b);
-// Global variable initialized at startup that is set to true if
-// CPU on which application runs supports POPCNT intrinsic. Unless
-// DISABLE_POPCNT_SUPPORT is defined.
-#if defined(DISABLE_POPCNT_SUPPORT)
-const bool CpuHasPOPCNT = false;
-#else
-const bool CpuHasPOPCNT = cpu_has_popcnt();
-#endif
-
-
-// Global variable used to print info about the use of 64 optimized
-// functions to verify that a 64bit compile has been correctly built.
-#if defined(BITCOUNT_SWAR_64)
-const bool CpuHas64BitPath = true;
-#else
-const bool CpuHas64BitPath = false;
-#endif
-
-
/// pop_1st_bit() finds and clears the least significant nonzero bit in a
/// nonzero bitboard. If template parameter is true an intrinsic is called,
/// otherwise we fallback on a software implementation.
/// pop_1st_bit() finds and clears the least significant nonzero bit in a
/// nonzero bitboard. If template parameter is true an intrinsic is called,
/// otherwise we fallback on a software implementation.
+
+// Global variable initialized at startup that is set to true if
+// CPU on which application runs supports POPCNT intrinsic. Unless
+// DISABLE_POPCNT_SUPPORT is defined.
+#if defined(DISABLE_POPCNT_SUPPORT)
+const bool CpuHasPOPCNT = false;
+#else
+const bool CpuHasPOPCNT = cpu_has_popcnt();
+#endif
+
+
+// Global variable used to print info about the use of 64 optimized
+// functions to verify that a 64bit compile has been correctly built.
+#if defined(BITCOUNT_SWAR_64)
+const bool CpuHas64BitPath = true;
+#else
+const bool CpuHas64BitPath = false;
+#endif
+
#endif // !defined(BITCOUNT_H_INCLUDED)
#endif // !defined(BITCOUNT_H_INCLUDED)
result += Value(square_distance(bksq, nsq) * 32);
// Bonus for restricting the knight's mobility
result += Value(square_distance(bksq, nsq) * 32);
// Bonus for restricting the knight's mobility
- result += Value((8 - count_1s_max_15<false>(pos.piece_attacks<KNIGHT>(nsq))) * 8);
+ result += Value((8 - count_1s_max_15(pos.piece_attacks<KNIGHT>(nsq))) * 8);
return (strongerSide == pos.side_to_move() ? result : -result);
}
return (strongerSide == pos.side_to_move() ? result : -result);
}
for (Bitboard b = 0ULL; b < 256ULL; b++)
{
for (Bitboard b = 0ULL; b < 256ULL; b++)
{
- assert(count_1s<false>(b) == int(uint8_t(count_1s<false>(b))));
- BitCount8Bit[b] = (uint8_t)count_1s<false>(b);
+ assert(count_1s(b) == int(uint8_t(count_1s(b))));
+ BitCount8Bit[b] = (uint8_t)count_1s(b);
// quality of the pawn shelter.
int attackUnits =
Min((ei.kingAttackersCount[them] * ei.kingAttackersWeight[them]) / 2, 25)
// quality of the pawn shelter.
int attackUnits =
Min((ei.kingAttackersCount[them] * ei.kingAttackersWeight[them]) / 2, 25)
- + (ei.kingAdjacentZoneAttacksCount[them] + count_1s_max_15<false>(undefended)) * 3
+ + (ei.kingAdjacentZoneAttacksCount[them] + count_1s_max_15(undefended)) * 3
+ InitKingDanger[relative_square(us, s)] - (shelter >> 5);
// Analyse safe queen contact checks
+ InitKingDanger[relative_square(us, s)] - (shelter >> 5);
// Analyse safe queen contact checks
{
// The bitboard b now contains the squares available for safe queen
// contact checks.
{
// The bitboard b now contains the squares available for safe queen
// contact checks.
- int count = count_1s_max_15<false>(b);
+ int count = count_1s_max_15(b);
attackUnits += QueenContactCheckBonus * count * (sente ? 2 : 1);
// Is there a mate threat?
attackUnits += QueenContactCheckBonus * count * (sente ? 2 : 1);
// Is there a mate threat?
// Queen checks
b2 = b & ei.attacked_by(them, QUEEN);
if( b2)
// Queen checks
b2 = b & ei.attacked_by(them, QUEEN);
if( b2)
- attackUnits += QueenCheckBonus * count_1s_max_15<false>(b2);
+ attackUnits += QueenCheckBonus * count_1s_max_15(b2);
// Rook checks
b2 = b & ei.attacked_by(them, ROOK);
if (b2)
// Rook checks
b2 = b & ei.attacked_by(them, ROOK);
if (b2)
- attackUnits += RookCheckBonus * count_1s_max_15<false>(b2);
+ attackUnits += RookCheckBonus * count_1s_max_15(b2);
}
if (QueenCheckBonus > 0 || BishopCheckBonus > 0)
{
}
if (QueenCheckBonus > 0 || BishopCheckBonus > 0)
{
// Queen checks
b2 = b & ei.attacked_by(them, QUEEN);
if (b2)
// Queen checks
b2 = b & ei.attacked_by(them, QUEEN);
if (b2)
- attackUnits += QueenCheckBonus * count_1s_max_15<false>(b2);
+ attackUnits += QueenCheckBonus * count_1s_max_15(b2);
// Bishop checks
b2 = b & ei.attacked_by(them, BISHOP);
if (b2)
// Bishop checks
b2 = b & ei.attacked_by(them, BISHOP);
if (b2)
- attackUnits += BishopCheckBonus * count_1s_max_15<false>(b2);
+ attackUnits += BishopCheckBonus * count_1s_max_15(b2);
}
if (KnightCheckBonus > 0)
{
}
if (KnightCheckBonus > 0)
{
// Knight checks
b2 = b & ei.attacked_by(them, KNIGHT);
if (b2)
// Knight checks
b2 = b & ei.attacked_by(them, KNIGHT);
if (b2)
- attackUnits += KnightCheckBonus * count_1s_max_15<false>(b2);
+ attackUnits += KnightCheckBonus * count_1s_max_15(b2);
}
// Analyse discovered checks (only for non-pawns right now, consider
}
// Analyse discovered checks (only for non-pawns right now, consider
{
b = p.discovered_check_candidates(them) & ~p.pawns();
if (b)
{
b = p.discovered_check_candidates(them) & ~p.pawns();
if (b)
- attackUnits += DiscoveredCheckBonus * count_1s_max_15<false>(b) * (sente? 2 : 1);
+ attackUnits += DiscoveredCheckBonus * count_1s_max_15(b) * (sente? 2 : 1);
}
// Has a mate threat been found? We don't do anything here if the
}
// Has a mate threat been found? We don't do anything here if the
if (d < 0)
{
int mtg = RANK_8 - relative_rank(us, s);
if (d < 0)
{
int mtg = RANK_8 - relative_rank(us, s);
- int blockerCount = count_1s_max_15<false>(squares_in_front_of(us,s) & pos.occupied_squares());
+ int blockerCount = count_1s_max_15(squares_in_front_of(us,s) & pos.occupied_squares());
mtg += blockerCount;
d += blockerCount;
if (d < 0)
mtg += blockerCount;
d += blockerCount;
if (d < 0)
behindFriendlyPawns |= (behindFriendlyPawns << 16);
}
behindFriendlyPawns |= (behindFriendlyPawns << 16);
}
- int space = count_1s_max_15<false>(safeSquares)
- + count_1s_max_15<false>(behindFriendlyPawns & safeSquares);
+ int space = count_1s_max_15(safeSquares)
+ + count_1s_max_15(behindFriendlyPawns & safeSquares);
ei.mgValue += Sign[us] * apply_weight(Value(space * ei.mi->space_weight()), WeightSpace);
}
ei.mgValue += Sign[us] * apply_weight(Value(space * ei.mi->space_weight()), WeightSpace);
}
// The checking pawn cannot be a discovered (bishop) check candidate
// otherwise we were in check also before last double push move.
assert(!bit_is_set(pos.discovered_check_candidates(them), checksq));
// The checking pawn cannot be a discovered (bishop) check candidate
// otherwise we were in check also before last double push move.
assert(!bit_is_set(pos.discovered_check_candidates(them), checksq));
- assert(count_1s<false>(b1) == 1 || count_1s<false>(b1) == 2);
+ assert(count_1s(b1) == 1 || count_1s(b1) == 2);
b1 &= ~pinned;
while (b1)
b1 &= ~pinned;
while (b1)
// Test for candidate passed pawn
candidate = !passed
&& pos.file_is_half_open(them, f)
// Test for candidate passed pawn
candidate = !passed
&& pos.file_is_half_open(them, f)
- && ( count_1s_max_15<false>(neighboring_files_bb(f) & (behind_bb(us, r) | rank_bb(r)) & ourPawns)
- - count_1s_max_15<false>(neighboring_files_bb(f) & in_front_bb(us, r) & theirPawns)
+ && ( count_1s_max_15(neighboring_files_bb(f) & (behind_bb(us, r) | rank_bb(r)) & ourPawns)
+ - count_1s_max_15(neighboring_files_bb(f) & in_front_bb(us, r) & theirPawns)
>= 0);
// In order to prevent doubled passed pawns from receiving a too big
>= 0);
// In order to prevent doubled passed pawns from receiving a too big
// Is there more than 2 checkers?
if (failedStep) (*failedStep)++;
// Is there more than 2 checkers?
if (failedStep) (*failedStep)++;
- if (debugCheckerCount && count_1s<false>(st->checkersBB) > 2)
+ if (debugCheckerCount && count_1s(st->checkersBB) > 2)
return false;
// Bitboards OK?
return false;
// Bitboards OK?
if (debugPieceCounts)
for (Color c = WHITE; c <= BLACK; c++)
for (PieceType pt = PAWN; pt <= KING; pt++)
if (debugPieceCounts)
for (Color c = WHITE; c <= BLACK; c++)
for (PieceType pt = PAWN; pt <= KING; pt++)
- if (pieceCount[c][pt] != count_1s<false>(pieces_of_color_and_type(c, pt)))
+ if (pieceCount[c][pt] != count_1s(pieces_of_color_and_type(c, pt)))
return false;
if (failedStep) (*failedStep)++;
return false;
if (failedStep) (*failedStep)++;