X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmisc.cpp;h=a5717e7a18553e578daf2ff5d486ef4ad64a19e5;hp=e6a29af78366684a28a3056e4f5a8f4c01964e66;hb=0436f01d05f05e2669cbb5b4bee752145b5b9991;hpb=06a853eb9c5173c30b31e75d0828c29dd65ebca4 diff --git a/src/misc.cpp b/src/misc.cpp index e6a29af7..a5717e7a 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -2,7 +2,7 @@ Stockfish, a UCI chess playing engine derived from Glaurung 2.1 Copyright (C) 2004-2008 Tord Romstad (Glaurung author) Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad - Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad + Copyright (C) 2015-2019 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad Stockfish is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -144,8 +144,79 @@ const string engine_info(bool to_uci) { } +/// compiler_info() returns a string trying to describe the compiler we use + +const std::string compiler_info() { + + #define STRINGIFY2(x) #x + #define STRINGIFY(x) STRINGIFY2(x) + #define VER_STRING(major, minor, patch) STRINGIFY(major) "." STRINGIFY(minor) "." STRINGIFY(patch) + +/// Predefined macros hell: +/// +/// __GNUC__ Compiler is gcc, Clang or Intel on Linux +/// __INTEL_COMPILER Compiler is Intel +/// _MSC_VER Compiler is MSVC or Intel on Windows +/// _WIN32 Building on Windows (any) +/// _WIN64 Building on Windows 64 bit + + std::string compiler = "\nCompiled by "; + + #ifdef __clang__ + compiler += "clang++ "; + compiler += VER_STRING(__clang_major__, __clang_minor__, __clang_patchlevel__); + #elif __INTEL_COMPILER + compiler += "Intel compiler "; + compiler += "(version "; + compiler += STRINGIFY(__INTEL_COMPILER) " update " STRINGIFY(__INTEL_COMPILER_UPDATE); + compiler += ")"; + #elif _MSC_VER + compiler += "MSVC "; + compiler += "(version "; + compiler += STRINGIFY(_MSC_FULL_VER) "." STRINGIFY(_MSC_BUILD); + compiler += ")"; + #elif __GNUC__ + compiler += "g++ (GNUC) "; + compiler += VER_STRING(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); + #else + compiler += "Unknown compiler "; + compiler += "(unknown version)"; + #endif + + #if defined(__APPLE__) + compiler += " on Apple"; + #elif defined(__CYGWIN__) + compiler += " on Cygwin"; + #elif defined(__MINGW64__) + compiler += " on MinGW64"; + #elif defined(__MINGW32__) + compiler += " on MinGW32"; + #elif defined(__ANDROID__) + compiler += " on Android"; + #elif defined(__linux__) + compiler += " on Linux"; + #elif defined(_WIN64) + compiler += " on Microsoft Windows 64-bit"; + #elif defined(_WIN32) + compiler += " on Microsoft Windows 32-bit"; + #else + compiler += " on unknown system"; + #endif + + compiler += "\n __VERSION__ macro expands to: "; + #ifdef __VERSION__ + compiler += __VERSION__; + #else + compiler += "(undefined macro)"; + #endif + compiler += "\n"; + + return compiler; +} + + /// Debug functions used mainly to collect run-time statistics -static int64_t hits[2], means[2]; +static std::atomic hits[2], means[2]; void dbg_hit_on(bool b) { ++hits[0]; if (b) ++hits[1]; } void dbg_hit_on(bool c, bool b) { if (c) dbg_hit_on(b); } @@ -210,12 +281,6 @@ void prefetch(void* addr) { #endif -void prefetch2(void* addr) { - - prefetch(addr); - prefetch((uint8_t*)addr + 64); -} - namespace WinProcGroup { #ifndef _WIN32 @@ -224,11 +289,11 @@ void bindThisThread(size_t) {} #else -/// get_group() retrieves logical processor information using Windows specific +/// best_group() retrieves logical processor information using Windows specific /// API and returns the best group id for the thread with index idx. Original /// code from Texel by Peter Österlund. -int get_group(size_t idx) { +int best_group(size_t idx) { int threads = 0; int nodes = 0; @@ -257,7 +322,7 @@ int get_group(size_t idx) { return -1; } - while (ptr->Size > 0 && byteOffset + ptr->Size <= returnLength) + while (byteOffset < returnLength) { if (ptr->Relationship == RelationNumaNode) nodes++; @@ -268,6 +333,7 @@ int get_group(size_t idx) { threads += (ptr->Processor.Flags == LTP_PC_SMT) ? 2 : 1; } + assert(ptr->Size); byteOffset += ptr->Size; ptr = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)(((char*)ptr) + ptr->Size); } @@ -299,7 +365,7 @@ int get_group(size_t idx) { void bindThisThread(size_t idx) { // Use only local variables to be thread-safe - int group = get_group(idx); + int group = best_group(idx); if (group == -1) return;