From 0c878adb36c1013944231083d6a7b3b53aa1ad7e Mon Sep 17 00:00:00 2001 From: Joost VandeVondele Date: Wed, 5 Feb 2020 15:18:24 +0100 Subject: [PATCH] Small cleanups. closes https://github.com/official-stockfish/Stockfish/pull/2532 Bench: 4869669 --- src/bitbase.cpp | 1 - src/endgame.h | 2 +- src/evaluate.cpp | 2 -- src/main.cpp | 2 +- src/misc.cpp | 14 +++++++------- src/misc.h | 2 +- src/movegen.cpp | 1 - src/position.cpp | 4 ++-- src/thread.cpp | 17 ++++++++--------- src/thread.h | 2 +- src/tt.cpp | 2 +- 11 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/bitbase.cpp b/src/bitbase.cpp index ed6ed208..bef2dc49 100644 --- a/src/bitbase.cpp +++ b/src/bitbase.cpp @@ -19,7 +19,6 @@ */ #include -#include #include #include diff --git a/src/endgame.h b/src/endgame.h index 4642e448..f6135354 100644 --- a/src/endgame.h +++ b/src/endgame.h @@ -21,10 +21,10 @@ #ifndef ENDGAME_H_INCLUDED #define ENDGAME_H_INCLUDED -#include #include #include #include +#include #include #include "position.h" diff --git a/src/evaluate.cpp b/src/evaluate.cpp index df7ff5ea..ceba2588 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -520,7 +520,6 @@ namespace { } // Bonus for restricting their piece moves - // Greater bonus when landing square is occupied b = attackedBy[Them][ALL_PIECES] & ~stronglyProtected & attackedBy[Us][ALL_PIECES]; @@ -721,7 +720,6 @@ namespace { - 43 * almostUnwinnable -110 ; - // Give more importance to non-material score Value mg = mg_value(score); Value eg = eg_value(score); diff --git a/src/main.cpp b/src/main.cpp index 148bf248..182cf105 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,12 +21,12 @@ #include #include "bitboard.h" +#include "endgame.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 { diff --git a/src/misc.cpp b/src/misc.cpp index cf18d2e2..4d6483e7 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -299,23 +299,23 @@ void prefetch(void* addr) { /// 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 - *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 -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 - *mem = malloc(size); - void* ret = reinterpret_cast((uintptr_t(*mem) + alignment - 1) & ~uintptr_t(alignment - 1)); + mem = malloc(size); + void* ret = reinterpret_cast((uintptr_t(mem) + alignment - 1) & ~uintptr_t(alignment - 1)); return ret; } diff --git a/src/misc.h b/src/misc.h index 45d9951a..a3780ba5 100644 --- a/src/misc.h +++ b/src/misc.h @@ -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); -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); diff --git a/src/movegen.cpp b/src/movegen.cpp index 8f6edffb..7e8961ae 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -52,7 +52,6 @@ namespace { template 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); diff --git a/src/position.cpp b/src/position.cpp index de9722ff..5efd9c42 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -633,11 +633,11 @@ bool Position::gives_check(Move m) const { 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? - if ( (st->blockersForKing[~sideToMove] & from) + if ( (blockers_for_king(~sideToMove) & from) && !aligned(from, to, square(~sideToMove))) return true; diff --git a/src/thread.cpp b/src/thread.cpp index 615d482c..10ec96dd 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -54,7 +54,7 @@ Thread::~Thread() { /// 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); @@ -71,14 +71,13 @@ void Thread::clear() { 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 diff --git a/src/thread.h b/src/thread.h index aea86fd5..63629e33 100644 --- a/src/thread.h +++ b/src/thread.h @@ -56,7 +56,7 @@ public: 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; diff --git a/src/tt.cpp b/src/tt.cpp index 46860fe9..7e95a2a4 100644 --- a/src/tt.cpp +++ b/src/tt.cpp @@ -66,7 +66,7 @@ void TranspositionTable::resize(size_t mbSize) { free(mem); clusterCount = mbSize * 1024 * 1024 / sizeof(Cluster); - table = static_cast(aligned_ttmem_alloc(clusterCount * sizeof(Cluster), &mem)); + table = static_cast(aligned_ttmem_alloc(clusterCount * sizeof(Cluster), mem)); if (!mem) { std::cerr << "Failed to allocate " << mbSize -- 2.39.2