X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Ftypes.h;h=364a4a5fc7d74d16ef2f8382b895fec1fd0213f7;hb=3c07603dac03f0da20194097cf4eb1a396fea60d;hp=c7ac4c643f4d1d4a559b6b21a6e7b06b3d9795a3;hpb=4eb2d8ce095b284a1e55762548d9821a83a19b3b;p=stockfish diff --git a/src/types.h b/src/types.h index c7ac4c64..364a4a5f 100644 --- a/src/types.h +++ b/src/types.h @@ -37,9 +37,15 @@ #include #include #include +#include #include -#include "platform.h" +#if defined(_MSC_VER) +// Disable some silly and noisy warning from MSVC compiler +#pragma warning(disable: 4127) // Conditional expression is constant +#pragma warning(disable: 4146) // Unary minus operator applied to unsigned type +#pragma warning(disable: 4800) // Forcing value to bool 'true' or 'false' +#endif /// Predefined macros hell: /// @@ -170,7 +176,7 @@ enum Bound { BOUND_EXACT = BOUND_UPPER | BOUND_LOWER }; -enum Value { +enum Value : int { VALUE_ZERO = 0, VALUE_DRAW = 0, VALUE_KNOWN_WIN = 10000, @@ -178,11 +184,8 @@ enum Value { VALUE_INFINITE = 32001, VALUE_NONE = 32002, - VALUE_MATE_IN_MAX_PLY = VALUE_MATE - 2 * MAX_PLY, - VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + 2 * MAX_PLY, - - VALUE_ENSURE_INTEGER_SIZE_P = INT_MAX, - VALUE_ENSURE_INTEGER_SIZE_N = INT_MIN, + VALUE_MATE_IN_MAX_PLY = VALUE_MATE - MAX_PLY, + VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + MAX_PLY, PawnValueMg = 198, PawnValueEg = 258, KnightValueMg = 817, KnightValueEg = 846, @@ -254,16 +257,10 @@ enum Rank { }; -/// Score enum stores a middlegame and an endgame value in a single integer. -/// The least significant 16 bits are used to store the endgame value and -/// the upper 16 bits are used to store the middlegame value. The compiler -/// is free to choose the enum type as long as it can store the data, so we -/// ensure that Score is an integer type by assigning some big int values. -enum Score { - SCORE_ZERO, - SCORE_ENSURE_INTEGER_SIZE_P = INT_MAX, - SCORE_ENSURE_INTEGER_SIZE_N = INT_MIN -}; +/// Score enum stores a middlegame and an endgame value in a single integer +/// (enum). The least significant 16 bits are used to store the endgame value +/// and the upper 16 bits are used to store the middlegame value. +enum Score : int { SCORE_ZERO }; inline Score make_score(int mg, int eg) { return Score((mg << 16) + eg); @@ -273,11 +270,15 @@ inline Score make_score(int mg, int eg) { /// according to the standard a simple cast to short is implementation defined /// and so is a right shift of a signed integer. inline Value mg_value(Score s) { - return Value(((s + 0x8000) & ~0xFFFF) / 0x10000); + + union { uint16_t u; int16_t s; } mg = { uint16_t(unsigned(s + 0x8000) >> 16) }; + return Value(mg.s); } inline Value eg_value(Score s) { - return Value((int)(unsigned(s) & 0x7FFFU) - (int)(unsigned(s) & 0x8000U)); + + union { uint16_t u; int16_t s; } eg = { uint16_t(unsigned(s)) }; + return Value(eg.s); } #define ENABLE_BASE_OPERATORS_ON(T) \