X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmisc.cpp;h=7ed4b443370ac5bf359deb13799fe679bbb22309;hp=2e43a76bb8f4a8fd95d1a7d2d18b478d28bc8e7f;hb=a010d438a2e378a82943835d49a53dfaa15c95d1;hpb=e81108a85519dedcb6d0ed8574f35a0b1c90ae97 diff --git a/src/misc.cpp b/src/misc.cpp index 2e43a76b..7ed4b443 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -39,6 +39,10 @@ #endif +#if !defined(NO_PREFETCH) +# include +#endif + #include #include #include @@ -287,4 +291,27 @@ int Bioskey() return 0; } } + #endif + +/// prefetch() preloads the given address in L1/L2 cache. This is a non +/// blocking function and do not stalls the CPU waiting for data to be +/// loaded from RAM, that can be very slow. +#if defined(NO_PREFETCH) +void prefetch(char*) {} +#else + +void prefetch(char* addr) { + +#if defined(__INTEL_COMPILER) || defined(__ICL) + // This hack prevents prefetches to be optimized away by + // Intel compiler. Both MSVC and gcc seems not affected. + __asm__ (""); +#endif + + _mm_prefetch(addr, _MM_HINT_T2); + _mm_prefetch(addr+64, _MM_HINT_T2); // 64 bytes ahead +} + +#endif +