From 99c9cae5865575c03a3eeea4ee6ea54ec8d59b18 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 7 Feb 2015 19:13:41 +0100 Subject: [PATCH] Avoid casting to char* in prefetch() Funny enough, gcc __builtin_prefetch() expects already a void*, instead Windows's _mm_prefetch() requires a char*. The patch allows to remove ugly casts from caller sites. No functional change. --- src/misc.cpp | 6 +++--- src/misc.h | 2 +- src/position.cpp | 6 +++--- src/search.cpp | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index 1674c2a6..daafd3fb 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -176,11 +176,11 @@ void start_logger(bool b) { Logger::start(b); } /// which can be quite slow. #ifdef NO_PREFETCH -void prefetch(char*) {} +void prefetch(void*) {} #else -void prefetch(char* addr) { +void prefetch(void* addr) { # if defined(__INTEL_COMPILER) // This hack prevents prefetches from being optimized away by @@ -189,7 +189,7 @@ void prefetch(char* addr) { # endif # if defined(__INTEL_COMPILER) || defined(_MSC_VER) - _mm_prefetch(addr, _MM_HINT_T0); + _mm_prefetch((char*)addr, _MM_HINT_T0); # else __builtin_prefetch(addr); # endif diff --git a/src/misc.h b/src/misc.h index 9d3c58c8..28bf0452 100644 --- a/src/misc.h +++ b/src/misc.h @@ -28,7 +28,7 @@ #include "types.h" const std::string engine_info(bool to_uci = false); -void prefetch(char* addr); +void prefetch(void* addr); void start_logger(bool b); void dbg_hit_on(bool b); diff --git a/src/position.cpp b/src/position.cpp index bb5a86f4..c02fdf62 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -774,7 +774,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI // Update material hash key and prefetch access to materialTable k ^= Zobrist::psq[them][captured][capsq]; st->materialKey ^= Zobrist::psq[them][captured][pieceCount[them][captured]]; - prefetch((char*)thisThread->materialTable[st->materialKey]); + prefetch(thisThread->materialTable[st->materialKey]); // Update incremental scores st->psq -= psq[them][captured][capsq]; @@ -841,7 +841,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI // Update pawn hash key and prefetch access to pawnsTable st->pawnKey ^= Zobrist::psq[us][PAWN][from] ^ Zobrist::psq[us][PAWN][to]; - prefetch((char*)thisThread->pawnsTable[st->pawnKey]); + prefetch(thisThread->pawnsTable[st->pawnKey]); // Reset rule 50 draw counter st->rule50 = 0; @@ -988,7 +988,7 @@ void Position::do_null_move(StateInfo& newSt) { } st->key ^= Zobrist::side; - prefetch((char*)TT.first_entry(st->key)); + prefetch(TT.first_entry(st->key)); ++st->rule50; st->pliesFromNull = 0; diff --git a/src/search.cpp b/src/search.cpp index 34fcc176..7f733a95 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -872,7 +872,7 @@ moves_loop: // When in check and at SpNode search starts from here } // Speculative prefetch as early as possible - prefetch((char*)TT.first_entry(pos.key_after(move))); + prefetch(TT.first_entry(pos.key_after(move))); // Check for legality just before making the move if (!RootNode && !SpNode && !pos.legal(move, ci.pinned)) @@ -1238,7 +1238,7 @@ moves_loop: // When in check and at SpNode search starts from here continue; // Speculative prefetch as early as possible - prefetch((char*)TT.first_entry(pos.key_after(move))); + prefetch(TT.first_entry(pos.key_after(move))); // Check for legality just before making the move if (!pos.legal(move, ci.pinned)) -- 2.39.2