official-stockfish / Stockfish

A free and strong UCI chess engine
https://stockfishchess.org/
GNU General Public License v3.0
11.61k stars 2.28k forks source link

icc (Intel C, Intel Parallel Studio XE 2019 Update 5) compilation errors #2412

Closed d3vv closed 4 years ago

d3vv commented 4 years ago
1>------ Rebuild All started: Project: Stockfish, Configuration: Release x64 ------
1>benchmark.cpp
1>bitbase.cpp
1>bitboard.cpp
1>endgame.cpp
1>evaluate.cpp
1>C:\msys64\home\dew\REPOS\Stockfish\src\evaluate.cpp(93): error : expression must have a constant value
1>    constexpr Score MobilityBonus[][32] = {
1>                                          ^
1>C:\msys64\home\dew\REPOS\Stockfish\src\evaluate.cpp(93): note: attempt to access run-time storage
1>    constexpr Score MobilityBonus[][32] = {
1>                                 ^
1>
1>main.cpp
1>material.cpp
1>C:\msys64\home\dew\REPOS\Stockfish\src\material.cpp(132): error : more than one instance of overloaded function "clamp" matches the argument list:
1>            function template "const T &clamp(const T &, const T &, const T &)"
1>            function template "const _Ty &std::clamp(const _Ty &, const _Ty &, const _Ty &)"
1>            argument types are: (Value, Value, Value)
1>    Value npm   = clamp(npm_w + npm_b, EndgameLimit, MidgameLimit);
1>                  ^
1>C:\msys64\home\dew\REPOS\Stockfish\src\material.cpp(132): note: this candidate was rejected because mismatch in count of arguments
1>    Value npm   = clamp(npm_w + npm_b, EndgameLimit, MidgameLimit);
1>                  ^
1>
1>misc.cpp
1>movegen.cpp
1>movepick.cpp
1>pawns.cpp
1>position.cpp
1>psqt.cpp
1>C:\msys64\home\dew\REPOS\Stockfish\src\psqt.cpp(38): error : expression must have a constant value
1>  constexpr Score Bonus[][RANK_NB][int(FILE_NB) / 2] = {
1>                                                       ^
1>C:\msys64\home\dew\REPOS\Stockfish\src\psqt.cpp(38): note: attempt to access run-time storage
1>  constexpr Score Bonus[][RANK_NB][int(FILE_NB) / 2] = {
1>                       ^
1>
1>C:\msys64\home\dew\REPOS\Stockfish\src\psqt.cpp(94): error : expression must have a constant value
1>    { // Pawn (asymmetric distribution)
1>    ^
1>C:\msys64\home\dew\REPOS\Stockfish\src\types.h(260): note: value exceeds range of "int"
1>    return Score((int)((unsigned int)eg << 16) + mg);
1>                                               ^
1>
1>search.cpp
1>tbprobe.cpp
1>thread.cpp
1>timeman.cpp
1>tt.cpp
1>uci.cpp
1>ucioption.cpp
1>Done building project "Stockfish.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Rocky640 commented 4 years ago

The message about std:: clamp conflicting with our home made clamp tells me that you are trying to compile with C++17. (std:;clamp is part of the STL since C++17) Stockfish had not yet been ported to C++17.

To fix this you can simply comment, in bitboard.h the following lines //template constexpr const T& clamp(const T& v, const T& lo, const T& hi) { //return v < lo ? lo : v > hi ? hi : v; //}

and wherever you see clamp, replace with std::clamp (or compile with c++14 or c++11)

For the other error messages, they are similar to the following issue encountered in the famous julia project https://github.com/JuliaLang/julia/issues/24952 Their conclusion was that "we do not support intel compiler"

However it seems that some effort was done in the past to support Intel in SF code. for example line 69 of timeman.cpp shows the following return TimePoint(myTime * std::min(ratio1, ratio2)); // Intel C++ asks for an explicit cast

I think that if you remove the constexpr before

constexpr Score MobilityBonus[][32] = {
constexpr Score Bonus[][RANK_NB][int(FILE_NB) / 2] = {
constexpr Score PBonus[RANK_NB][FILE_NB] =

it will compile correctly, although with some warnings.

d3vv commented 4 years ago

@Rocky640 You are right at all.

There is was no problem to compile SF via Intel Compiler time ago.

Now I can't choose C++11 at Visual Studio 2019 IDE (only C++14, 17 and Latest C++ Draft Standard) But constexpr-errors persist also if I choose C++14 with IDE or C++11 with Command Line Tools. This is from most stronger standard for constexpr.

As about home made clamp - it is strange to use "using namespace std;" in any cases.. And don't use something like "custom::clamp"..

And more about effort to support Intel in SF code:

$ grep INTEL *
bitboard.h:#elif defined(_MSC_VER) || defined(__INTEL_COMPILER)
misc.cpp:#  if defined(__INTEL_COMPILER)
misc.cpp:#  if defined(__INTEL_COMPILER) || defined(_MSC_VER)
types.h:/// __INTEL_COMPILER   Compiler is Intel
types.h:#if defined(USE_POPCNT) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
types.h:#if !defined(NO_PREFETCH) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
gvreuls commented 4 years ago

Could the constexpr errors be due to the c-style casts? Perhaps c-style casts aren't constexpr in modern intel compilers? I can't test this myself unfortunately.

d3vv commented 4 years ago

@gvreuls I will try to investigate all a bit later.. Just I'm under pressure and the rest needed But! Thousands C-style casts into the code it is sadly.. Nobody knows what is it - static, dynamic, reinterpret, const or void into the mind..

d3vv commented 4 years ago

And at first glance it is very strange to use the voids into constexpr like laconic { }, Cause constexpr has real cruel limitations into c++11 and a bit softly into latest standards..

d3vv commented 4 years ago

@andrey-budko Could u suggest thoughts about ur godbolt-link above? По-руcски: Ваши соображения по поводу анализа этого кода?

snicolet commented 4 years ago

Not an issue until we switch to C++17