]> git.sesse.net Git - stockfish/commitdiff
Small cleanups.
authorJoost VandeVondele <Joost.VandeVondele@gmail.com>
Wed, 5 Feb 2020 14:18:24 +0000 (15:18 +0100)
committerJoost VandeVondele <Joost.VandeVondele@gmail.com>
Wed, 5 Feb 2020 14:32:29 +0000 (15:32 +0100)
closes https://github.com/official-stockfish/Stockfish/pull/2532

Bench: 4869669

src/bitbase.cpp
src/endgame.h
src/evaluate.cpp
src/main.cpp
src/misc.cpp
src/misc.h
src/movegen.cpp
src/position.cpp
src/thread.cpp
src/thread.h
src/tt.cpp

index ed6ed2088e19b3c0bd5e19278645ea151ba0b1be..bef2dc49e2f1a91816dbacfd55ebcf975d312276 100644 (file)
@@ -19,7 +19,6 @@
 */
 
 #include <cassert>
 */
 
 #include <cassert>
-#include <numeric>
 #include <vector>
 #include <bitset>
 
 #include <vector>
 #include <bitset>
 
index 4642e44857b4ac7500652941f57243ea736e5260..f61353542aa13f62ac78d41079f2f1ca5e66cdf9 100644 (file)
 #ifndef ENDGAME_H_INCLUDED
 #define ENDGAME_H_INCLUDED
 
 #ifndef ENDGAME_H_INCLUDED
 #define ENDGAME_H_INCLUDED
 
-#include <unordered_map>
 #include <memory>
 #include <string>
 #include <type_traits>
 #include <memory>
 #include <string>
 #include <type_traits>
+#include <unordered_map>
 #include <utility>
 
 #include "position.h"
 #include <utility>
 
 #include "position.h"
index df7ff5ea33776e61eb7fb75fa9365d58bc4c1128..ceba25881058d8135a0f50cdff3afc44d56ea4de 100644 (file)
@@ -520,7 +520,6 @@ namespace {
     }
 
     // Bonus for restricting their piece moves
     }
 
     // Bonus for restricting their piece moves
-    // Greater bonus when landing square is occupied
     b =   attackedBy[Them][ALL_PIECES]
        & ~stronglyProtected
        &  attackedBy[Us][ALL_PIECES];
     b =   attackedBy[Them][ALL_PIECES]
        & ~stronglyProtected
        &  attackedBy[Us][ALL_PIECES];
@@ -721,7 +720,6 @@ namespace {
                     - 43 * almostUnwinnable
                     -110 ;
 
                     - 43 * almostUnwinnable
                     -110 ;
 
-    // Give more importance to non-material score
     Value mg = mg_value(score);
     Value eg = eg_value(score);
 
     Value mg = mg_value(score);
     Value eg = eg_value(score);
 
index 148bf248f5337aec842666bdeb42df8d163837b1..182cf105edcfc8808ffc425b063282f685f27244 100644 (file)
 #include <iostream>
 
 #include "bitboard.h"
 #include <iostream>
 
 #include "bitboard.h"
+#include "endgame.h"
 #include "position.h"
 #include "search.h"
 #include "thread.h"
 #include "tt.h"
 #include "uci.h"
 #include "position.h"
 #include "search.h"
 #include "thread.h"
 #include "tt.h"
 #include "uci.h"
-#include "endgame.h"
 #include "syzygy/tbprobe.h"
 
 namespace PSQT {
 #include "syzygy/tbprobe.h"
 
 namespace PSQT {
index cf18d2e2fc56b826f3e627d712f02d8ff96e9f1d..4d6483e73d20f78d352429bbc24289a648fc3649 100644 (file)
@@ -299,23 +299,23 @@ void prefetch(void* addr) {
 /// With c++17 some of this functionality can be simplified.
 #if defined(__linux__) && !defined(__ANDROID__)
 
 /// With c++17 some of this functionality can be simplified.
 #if defined(__linux__) && !defined(__ANDROID__)
 
-void* aligned_ttmem_alloc(size_t allocSize, void** mem) {
+void* aligned_ttmem_alloc(size_t allocSize, void*& mem) {
 
   constexpr size_t alignment = 2 * 1024 * 1024; // assumed 2MB page sizes
   size_t size = ((allocSize + alignment - 1) / alignment) * alignment; // multiple of alignment
 
   constexpr size_t alignment = 2 * 1024 * 1024; // assumed 2MB page sizes
   size_t size = ((allocSize + alignment - 1) / alignment) * alignment; // multiple of alignment
-  *mem = aligned_alloc(alignment, size);
-  madvise(*mem, allocSize, MADV_HUGEPAGE);
-  return *mem;
+  mem = aligned_alloc(alignment, size);
+  madvise(mem, allocSize, MADV_HUGEPAGE);
+  return mem;
 }
 
 #else
 
 }
 
 #else
 
-void* aligned_ttmem_alloc(size_t allocSize, void** mem) {
+void* aligned_ttmem_alloc(size_t allocSize, void*& mem) {
 
   constexpr size_t alignment = 64; // assumed cache line size
   size_t size = allocSize + alignment - 1; // allocate some extra space
 
   constexpr size_t alignment = 64; // assumed cache line size
   size_t size = allocSize + alignment - 1; // allocate some extra space
-  *mem = malloc(size);
-  void* ret = reinterpret_cast<void*>((uintptr_t(*mem) + alignment - 1) & ~uintptr_t(alignment - 1));
+  mem = malloc(size);
+  void* ret = reinterpret_cast<void*>((uintptr_t(mem) + alignment - 1) & ~uintptr_t(alignment - 1));
   return ret;
 }
 
   return ret;
 }
 
index 45d9951a72aa4edfb0997a5102dd2bfbf841648f..a3780ba599d1ce6746d8edfa533d1517e8128ade 100644 (file)
@@ -33,7 +33,7 @@ const std::string engine_info(bool to_uci = false);
 const std::string compiler_info();
 void prefetch(void* addr);
 void start_logger(const std::string& fname);
 const std::string compiler_info();
 void prefetch(void* addr);
 void start_logger(const std::string& fname);
-void* aligned_ttmem_alloc(size_t size, void** mem);
+void* aligned_ttmem_alloc(size_t size, void*& mem);
 
 void dbg_hit_on(bool b);
 void dbg_hit_on(bool c, bool b);
 
 void dbg_hit_on(bool b);
 void dbg_hit_on(bool c, bool b);
index 8f6edffbfc33da9034530038912dadbbc1eb1dc5..7e8961ae3b60603e35698c44277c2a6ed72656c6 100644 (file)
@@ -52,7 +52,6 @@ namespace {
   template<Color Us, GenType Type>
   ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) {
 
   template<Color Us, GenType Type>
   ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) {
 
-    // Compute some compile time parameters relative to the white side
     constexpr Color     Them     = (Us == WHITE ? BLACK      : WHITE);
     constexpr Bitboard  TRank7BB = (Us == WHITE ? Rank7BB    : Rank2BB);
     constexpr Bitboard  TRank3BB = (Us == WHITE ? Rank3BB    : Rank6BB);
     constexpr Color     Them     = (Us == WHITE ? BLACK      : WHITE);
     constexpr Bitboard  TRank7BB = (Us == WHITE ? Rank7BB    : Rank2BB);
     constexpr Bitboard  TRank3BB = (Us == WHITE ? Rank3BB    : Rank6BB);
index de9722fff2b9a098d1fcf5c1cb98a011f878d4df..5efd9c42a5eb351df1c043ea0b1e25a84b28f935 100644 (file)
@@ -633,11 +633,11 @@ bool Position::gives_check(Move m) const {
   Square to = to_sq(m);
 
   // Is there a direct check?
   Square to = to_sq(m);
 
   // Is there a direct check?
-  if (st->checkSquares[type_of(piece_on(from))] & to)
+  if (check_squares(type_of(piece_on(from))) & to)
       return true;
 
   // Is there a discovered check?
       return true;
 
   // Is there a discovered check?
-  if (   (st->blockersForKing[~sideToMove] & from)
+  if (   (blockers_for_king(~sideToMove) & from)
       && !aligned(from, to, square<KING>(~sideToMove)))
       return true;
 
       && !aligned(from, to, square<KING>(~sideToMove)))
       return true;
 
index 615d482cafa811a4046eaacf7f21676b28f46ed6..10ec96dddbae31005fb2fee3c79e0753e34d41eb 100644 (file)
@@ -54,7 +54,7 @@ Thread::~Thread() {
 
 /// Thread::bestMoveCount(Move move) return best move counter for the given root move
 
 
 /// Thread::bestMoveCount(Move move) return best move counter for the given root move
 
-int Thread::best_move_count(Move move) {
+int Thread::best_move_count(Move move) const {
 
   auto rm = std::find(rootMoves.begin() + pvIdx,
                       rootMoves.begin() + pvLast, move);
 
   auto rm = std::find(rootMoves.begin() + pvIdx,
                       rootMoves.begin() + pvLast, move);
@@ -71,14 +71,13 @@ void Thread::clear() {
   captureHistory.fill(0);
 
   for (bool inCheck : { false, true })
   captureHistory.fill(0);
 
   for (bool inCheck : { false, true })
-    for (StatsType c : { NoCaptures, Captures })
-      for (auto& to : continuationHistory[inCheck][c])
-        for (auto& h : to)
-          h->fill(0);
-
-  for (bool inCheck : { false, true })
-    for (StatsType c : { NoCaptures, Captures })
-      continuationHistory[inCheck][c][NO_PIECE][0]->fill(Search::CounterMovePruneThreshold - 1);
+      for (StatsType c : { NoCaptures, Captures })
+      {
+          for (auto& to : continuationHistory[inCheck][c])
+                for (auto& h : to)
+                      h->fill(0);
+          continuationHistory[inCheck][c][NO_PIECE][0]->fill(Search::CounterMovePruneThreshold - 1);
+      }
 }
 
 /// Thread::start_searching() wakes up the thread that will start the search
 }
 
 /// Thread::start_searching() wakes up the thread that will start the search
index aea86fd5c6941312fcf9a5b04ac2c56d2cc67fbd..63629e338124e5a6e12a44205698205c601be29c 100644 (file)
@@ -56,7 +56,7 @@ public:
   void idle_loop();
   void start_searching();
   void wait_for_search_finished();
   void idle_loop();
   void start_searching();
   void wait_for_search_finished();
-  int best_move_count(Move move);
+  int best_move_count(Move move) const;
 
   Pawns::Table pawnsTable;
   Material::Table materialTable;
 
   Pawns::Table pawnsTable;
   Material::Table materialTable;
index 46860fe900df5b9157d3cbafa5e932c688e0de83..7e95a2a4e6dbcd74f374dd534b1b611fd2787a62 100644 (file)
@@ -66,7 +66,7 @@ void TranspositionTable::resize(size_t mbSize) {
   free(mem);
 
   clusterCount = mbSize * 1024 * 1024 / sizeof(Cluster);
   free(mem);
 
   clusterCount = mbSize * 1024 * 1024 / sizeof(Cluster);
-  table = static_cast<Cluster*>(aligned_ttmem_alloc(clusterCount * sizeof(Cluster), &mem));
+  table = static_cast<Cluster*>(aligned_ttmem_alloc(clusterCount * sizeof(Cluster), mem));
   if (!mem)
   {
       std::cerr << "Failed to allocate " << mbSize
   if (!mem)
   {
       std::cerr << "Failed to allocate " << mbSize