Skip to content

Commit

Permalink
Avoid casting to char* in prefetch()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mcostalba committed Feb 7, 2015
1 parent 152a4dc commit 99c9cae
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/misc.cpp
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/misc.h
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/position.cpp
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/search.cpp
Expand Up @@ -872,7 +872,7 @@ namespace {
}

// 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))
Expand Down Expand Up @@ -1238,7 +1238,7 @@ namespace {
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))
Expand Down

0 comments on commit 99c9cae

Please sign in to comment.