Unify BitCountType selection

Now that HasPopCnt is a compile time constant we can
centralize and unify the BitCountType selection.

Also rename count_1s() in the more standard popcount()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba
2011-12-31 09:46:43 +01:00
parent fb4b4f772e
commit e9296d694c
6 changed files with 50 additions and 44 deletions
+13 -20
View File
@@ -422,7 +422,6 @@ namespace {
template<Color Us>
void init_eval_info(const Position& pos, EvalInfo& ei) {
const BitCountType Max15 = HasPopCnt ? CNT_POPCNT : Is64Bit ? CNT64_MAX15 : CNT32_MAX15;
const Color Them = (Us == WHITE ? BLACK : WHITE);
Bitboard b = ei.attackedBy[Them][KING] = pos.attacks_from<KING>(pos.king_square(Them));
@@ -434,7 +433,7 @@ namespace {
{
ei.kingRing[Them] = (b | (Us == WHITE ? b >> 8 : b << 8));
b &= ei.attackedBy[Us][PAWN];
ei.kingAttackersCount[Us] = b ? count_1s<Max15>(b) / 2 : 0;
ei.kingAttackersCount[Us] = b ? popcount<Max15>(b) / 2 : 0;
ei.kingAdjacentZoneAttacksCount[Us] = ei.kingAttackersWeight[Us] = 0;
} else
ei.kingRing[Them] = ei.kingAttackersCount[Us] = 0;
@@ -478,8 +477,6 @@ namespace {
File f;
Score score = SCORE_ZERO;
const BitCountType Full = HasPopCnt ? CNT_POPCNT : Is64Bit ? CNT64 : CNT32;
const BitCountType Max15 = HasPopCnt ? CNT_POPCNT : Is64Bit ? CNT64_MAX15 : CNT32_MAX15;
const Color Them = (Us == WHITE ? BLACK : WHITE);
const Square* pl = pos.piece_list(Us, Piece);
@@ -507,12 +504,12 @@ namespace {
ei.kingAttackersWeight[Us] += KingAttackWeights[Piece];
Bitboard bb = (b & ei.attackedBy[Them][KING]);
if (bb)
ei.kingAdjacentZoneAttacksCount[Us] += count_1s<Max15>(bb);
ei.kingAdjacentZoneAttacksCount[Us] += popcount<Max15>(bb);
}
// Mobility
mob = (Piece != QUEEN ? count_1s<Max15>(b & mobilityArea)
: count_1s<Full >(b & mobilityArea));
mob = (Piece != QUEEN ? popcount<Max15>(b & mobilityArea)
: popcount<Full >(b & mobilityArea));
mobility += MobilityBonus[Piece][mob];
@@ -667,7 +664,6 @@ namespace {
template<Color Us, bool Trace>
Score evaluate_king(const Position& pos, EvalInfo& ei, Value margins[]) {
const BitCountType Max15 = HasPopCnt ? CNT_POPCNT : Is64Bit ? CNT64_MAX15 : CNT32_MAX15;
const Color Them = (Us == WHITE ? BLACK : WHITE);
Bitboard undefended, b, b1, b2, safe;
@@ -695,7 +691,7 @@ namespace {
// attacked and undefended squares around our king, the square of the
// king, and the quality of the pawn shelter.
attackUnits = std::min(25, (ei.kingAttackersCount[Them] * ei.kingAttackersWeight[Them]) / 2)
+ 3 * (ei.kingAdjacentZoneAttacksCount[Them] + count_1s<Max15>(undefended))
+ 3 * (ei.kingAdjacentZoneAttacksCount[Them] + popcount<Max15>(undefended))
+ InitKingDanger[relative_square(Us, ksq)]
- mg_value(ei.pi->king_shelter<Us>(pos, ksq)) / 32;
@@ -709,7 +705,7 @@ namespace {
| ei.attackedBy[Them][BISHOP] | ei.attackedBy[Them][ROOK]);
if (b)
attackUnits += QueenContactCheckBonus
* count_1s<Max15>(b)
* popcount<Max15>(b)
* (Them == pos.side_to_move() ? 2 : 1);
}
@@ -727,7 +723,7 @@ namespace {
| ei.attackedBy[Them][BISHOP] | ei.attackedBy[Them][QUEEN]);
if (b)
attackUnits += RookContactCheckBonus
* count_1s<Max15>(b)
* popcount<Max15>(b)
* (Them == pos.side_to_move() ? 2 : 1);
}
@@ -740,22 +736,22 @@ namespace {
// Enemy queen safe checks
b = (b1 | b2) & ei.attackedBy[Them][QUEEN];
if (b)
attackUnits += QueenCheckBonus * count_1s<Max15>(b);
attackUnits += QueenCheckBonus * popcount<Max15>(b);
// Enemy rooks safe checks
b = b1 & ei.attackedBy[Them][ROOK];
if (b)
attackUnits += RookCheckBonus * count_1s<Max15>(b);
attackUnits += RookCheckBonus * popcount<Max15>(b);
// Enemy bishops safe checks
b = b2 & ei.attackedBy[Them][BISHOP];
if (b)
attackUnits += BishopCheckBonus * count_1s<Max15>(b);
attackUnits += BishopCheckBonus * popcount<Max15>(b);
// Enemy knights safe checks
b = pos.attacks_from<KNIGHT>(ksq) & ei.attackedBy[Them][KNIGHT] & safe;
if (b)
attackUnits += KnightCheckBonus * count_1s<Max15>(b);
attackUnits += KnightCheckBonus * popcount<Max15>(b);
// To index KingDangerTable[] attackUnits must be in [0, 99] range
attackUnits = std::min(99, std::max(0, attackUnits));
@@ -879,8 +875,6 @@ namespace {
Score evaluate_unstoppable_pawns(const Position& pos, EvalInfo& ei) {
const BitCountType Max15 = HasPopCnt ? CNT_POPCNT : Is64Bit ? CNT64_MAX15 : CNT32_MAX15;
Bitboard b, b2, blockers, supporters, queeningPath, candidates;
Square s, blockSq, queeningSquare;
Color c, winnerSide, loserSide;
@@ -918,7 +912,7 @@ namespace {
assert((queeningPath & pos.occupied_squares()) == (queeningPath & pos.pieces(c)));
// Add moves needed to free the path from friendly pieces and retest condition
movesToGo += count_1s<Max15>(queeningPath & pos.pieces(c));
movesToGo += popcount<Max15>(queeningPath & pos.pieces(c));
if (movesToGo >= oppMovesToGo && !pathDefended)
continue;
@@ -1046,7 +1040,6 @@ namespace {
template<Color Us>
int evaluate_space(const Position& pos, EvalInfo& ei) {
const BitCountType Max15 = HasPopCnt ? CNT_POPCNT : Is64Bit ? CNT64_MAX15 : CNT32_MAX15;
const Color Them = (Us == WHITE ? BLACK : WHITE);
// Find the safe squares for our pieces inside the area defined by
@@ -1062,7 +1055,7 @@ namespace {
behind |= (Us == WHITE ? behind >> 8 : behind << 8);
behind |= (Us == WHITE ? behind >> 16 : behind << 16);
return count_1s<Max15>(safe) + count_1s<Max15>(behind & safe);
return popcount<Max15>(safe) + popcount<Max15>(behind & safe);
}