X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Ftypes.h;h=5fee1786f77564b060afbc3719a3f21f134fa8fb;hp=f74ba8d52fedd04b798c9528141e5420456e61cb;hb=6f48367094082ad03526f6ffe24d7c3873ff7386;hpb=c9e396b5424802b80e80394979ca84688b523244 diff --git a/src/types.h b/src/types.h index f74ba8d5..5fee1786 100644 --- a/src/types.h +++ b/src/types.h @@ -136,7 +136,7 @@ enum CastlingSide { KING_SIDE, QUEEN_SIDE, CASTLING_SIDE_NB = 2 }; -enum CastlingRight { // Defined as in PolyGlot book hash key +enum CastlingRight { NO_CASTLING, WHITE_OO, WHITE_OOO = WHITE_OO << 1, @@ -267,28 +267,30 @@ enum Score { SCORE_ENSURE_INTEGER_SIZE_N = INT_MIN }; -inline Score make_score(int mg, int eg) { return Score((mg << 16) + eg); } +typedef union { + uint32_t full; + struct { int16_t eg, mg; } half; +} ScoreView; -/// Extracting the signed lower and upper 16 bits is not so trivial because -/// 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); } - -/// On Intel 64 bit we have a small speed regression with the standard conforming -/// version. Therefore, in this case we use faster code that, although not 100% -/// standard compliant, seems to work for Intel and MSVC. -#if defined(IS_64BIT) && (!defined(__GNUC__) || defined(__INTEL_COMPILER)) - -inline Value eg_value(Score s) { return Value(int16_t(s & 0xFFFF)); } +inline Score make_score(int mg, int eg) { + ScoreView v; + v.half.mg = (int16_t)(mg - (uint16_t(eg) >> 15)); + v.half.eg = (int16_t)eg; + return Score(v.full); +} -#else +inline Value mg_value(Score s) { + ScoreView v; + v.full = s; + return Value(v.half.mg + (uint16_t(v.half.eg) >> 15)); +} inline Value eg_value(Score s) { - return Value((int)(unsigned(s) & 0x7FFFU) - (int)(unsigned(s) & 0x8000U)); + ScoreView v; + v.full = s; + return Value(v.half.eg); } -#endif - #define ENABLE_BASE_OPERATORS_ON(T) \ inline T operator+(const T d1, const T d2) { return T(int(d1) + int(d2)); } \ inline T operator-(const T d1, const T d2) { return T(int(d1) - int(d2)); } \