]> git.sesse.net Git - stockfish/commitdiff
Use compiler name lookup to simplify code
authorMarco Costalba <mcostalba@gmail.com>
Sun, 24 May 2009 09:15:23 +0000 (10:15 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 24 May 2009 09:18:31 +0000 (10:18 +0100)
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>
src/bitboard.cpp
src/bitcount.h
src/endgame.cpp
src/evaluate.cpp
src/movegen.cpp
src/pawns.cpp
src/position.cpp

index 3dfa040b8e2b0bd513926fd546a6ea4ba85b8382..a73c5a2dc7ad970d6c8f16275ead918d2af46ac1 100644 (file)
@@ -461,7 +461,7 @@ namespace {
 
 
   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);
index 41a1446e01b700b7d6fa08b9425b1a199a2a9122..871247abcf4be72b16df1def8d04f97a6e6d8f52 100644 (file)
@@ -86,8 +86,8 @@ inline bool cpu_has_popcnt() {
 
 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
 
 #endif
 
@@ -96,19 +96,19 @@ inline bool cpu_has_popcnt() { return false; }
 
 #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;
 }
 
-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)
 
-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;
@@ -120,7 +120,7 @@ inline int sw_count_1s(Bitboard b) {
   return int(v >> 24);
 }
 
-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;
@@ -133,7 +133,7 @@ inline int sw_count_1s_max_15(Bitboard b) {
 
 #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;
@@ -141,7 +141,7 @@ inline int sw_count_1s(Bitboard b) {
   return int(b >> 56);
 }
 
-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;
@@ -158,35 +158,16 @@ inline int sw_count_1s_max_15(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) {
 
-  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.
@@ -207,4 +188,23 @@ inline Square pop_1st_bit<true>(Bitboard *b) {
   return Square(idx);
 }
 
+
+// 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)
index 90898e8341a58987b46cb0433018cb4d587484e8..3258c6fc18ac02af42fbd474dbacd699a2de99dd 100644 (file)
@@ -378,7 +378,7 @@ Value EvaluationFunction<KBBKN>::apply(const Position& pos) {
   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);
 }
index 1d4be67b2d0e7c3d4c5405c64ea6ebda36444aa2..9fd4040ef2ee161291dfc8fdab6269b343efbaad 100644 (file)
@@ -494,8 +494,8 @@ void init_eval(int threads) {
 
   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);
   }
 }
 
@@ -757,7 +757,7 @@ namespace {
       // 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
@@ -773,7 +773,7 @@ namespace {
         {
           // 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?
@@ -813,12 +813,12 @@ namespace {
           // 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)
-              attackUnits += RookCheckBonus * count_1s_max_15<false>(b2);
+              attackUnits += RookCheckBonus * count_1s_max_15(b2);
       }
       if (QueenCheckBonus > 0 || BishopCheckBonus > 0)
       {
@@ -827,12 +827,12 @@ namespace {
           // 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)
-              attackUnits += BishopCheckBonus * count_1s_max_15<false>(b2);
+              attackUnits += BishopCheckBonus * count_1s_max_15(b2);
       }
       if (KnightCheckBonus > 0)
       {
@@ -841,7 +841,7 @@ namespace {
           // 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
@@ -850,7 +850,7 @@ namespace {
       {
         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
@@ -985,7 +985,7 @@ namespace {
                 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)
@@ -1146,8 +1146,8 @@ namespace {
         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);
   }
index dbdb0875b658b3ac197215e6572e22093c9c5117..a76d9f7c8e403b35dee1c7f2429310e6d020bf08 100644 (file)
@@ -352,7 +352,7 @@ int generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pinned) {
           // 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)
index 08b0e7ba0fc32288dfcedb551bef82a89b197df1..19bf6c51d8fb067b538f1219b77c4c70ab3068ed 100644 (file)
@@ -330,8 +330,8 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
         // 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
index 6e6bf38b3dda159a5703386f3d7e1fe192d693ab..dd6ec05b929d70088c68fd8a3aa40b77486680fb 100644 (file)
@@ -2091,7 +2091,7 @@ bool Position::is_ok(int* failedStep) const {
 
   // 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?
@@ -2166,7 +2166,7 @@ bool Position::is_ok(int* failedStep) const {
   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)++;