Skip to content

Commit 9f800a2

Browse files
committed
Show compiler info at startup
This patch shows a description of the compiler used to compile Stockfish, when starting from the console. Usage: ``` ./stockfish compiler ``` Example of output: ``` Stockfish 120120 64 POPCNT by T. Romstad, M. Costalba, J. Kiiski, G. Linscott Compiled by clang++ 9.0.0 on Apple __VERSION__ macro expands to: 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.38) ``` No functional change
1 parent 114ddb7 commit 9f800a2

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

src/misc.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,77 @@ const string engine_info(bool to_uci) {
151151
}
152152

153153

154+
/// compiler_info() returns a string trying to describe the compiler we use
155+
156+
const std::string compiler_info() {
157+
158+
#define STRINGIFY2(x) #x
159+
#define STRINGIFY(x) STRINGIFY2(x)
160+
#define VER_STRING(major, minor, patch) STRINGIFY(major) "." STRINGIFY(minor) "." STRINGIFY(patch)
161+
162+
/// Predefined macros hell:
163+
///
164+
/// __GNUC__ Compiler is gcc, Clang or Intel on Linux
165+
/// __INTEL_COMPILER Compiler is Intel
166+
/// _MSC_VER Compiler is MSVC or Intel on Windows
167+
/// _WIN32 Building on Windows (any)
168+
/// _WIN64 Building on Windows 64 bit
169+
170+
std::string compiler = "\nCompiled by ";
171+
172+
#ifdef __clang__
173+
compiler += "clang++ ";
174+
compiler += VER_STRING(__clang_major__, __clang_minor__, __clang_patchlevel__);
175+
#elif __INTEL_COMPILER
176+
compiler += "Intel compiler ";
177+
compiler += "(version ";
178+
compiler += STRINGIFY(__INTEL_COMPILER) " update " STRINGIFY(__INTEL_COMPILER_UPDATE);
179+
compiler += ")";
180+
#elif _MSC_VER
181+
compiler += "MSVC ";
182+
compiler += "(version ";
183+
compiler += STRINGIFY(_MSC_FULL_VER) "." STRINGIFY(_MSC_BUILD);
184+
compiler += ")";
185+
#elif __GNUC__
186+
compiler += "g++ (GNUC) ";
187+
compiler += VER_STRING(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
188+
#else
189+
compiler += "Unknown compiler ";
190+
compiler += "(unknown version)";
191+
#endif
192+
193+
#if defined(__APPLE__)
194+
compiler += " on Apple";
195+
#elif defined(__CYGWIN__)
196+
compiler += " on Cygwin";
197+
#elif defined(__MINGW64__)
198+
compiler += " on MinGW64";
199+
#elif defined(__MINGW32__)
200+
compiler += " on MinGW32";
201+
#elif defined(__ANDROID__)
202+
compiler += " on Android";
203+
#elif defined(__linux__)
204+
compiler += " on Linux";
205+
#elif defined(_WIN64)
206+
compiler += " on Microsoft Windows 64-bit";
207+
#elif defined(_WIN32)
208+
compiler += " on Microsoft Windows 32-bit";
209+
#else
210+
compiler += " on unknown system";
211+
#endif
212+
213+
compiler += "\n __VERSION__ macro expands to: ";
214+
#ifdef __VERSION__
215+
compiler += __VERSION__;
216+
#else
217+
compiler += "(undefined macro)";
218+
#endif
219+
compiler += "\n";
220+
221+
return compiler;
222+
}
223+
224+
154225
/// Debug functions used mainly to collect run-time statistics
155226
static std::atomic<int64_t> hits[2], means[2];
156227

src/misc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "types.h"
3131

3232
const std::string engine_info(bool to_uci = false);
33+
const std::string compiler_info();
3334
void prefetch(void* addr);
3435
void start_logger(const std::string& fname);
3536

src/uci.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,11 @@ void UCI::loop(int argc, char* argv[]) {
235235

236236
// Additional custom non-UCI commands, mainly for debugging.
237237
// Do not use these commands during a search!
238-
else if (token == "flip") pos.flip();
239-
else if (token == "bench") bench(pos, is, states);
240-
else if (token == "d") sync_cout << pos << sync_endl;
241-
else if (token == "eval") sync_cout << Eval::trace(pos) << sync_endl;
238+
else if (token == "flip") pos.flip();
239+
else if (token == "bench") bench(pos, is, states);
240+
else if (token == "d") sync_cout << pos << sync_endl;
241+
else if (token == "eval") sync_cout << Eval::trace(pos) << sync_endl;
242+
else if (token == "compiler") sync_cout << compiler_info() << sync_endl;
242243
else
243244
sync_cout << "Unknown command: " << cmd << sync_endl;
244245

0 commit comments

Comments
 (0)