]> git.sesse.net Git - stockfish/blobdiff - src/types.h
Fix a warning with MSVC Premium 2013
[stockfish] / src / types.h
index 9bfe9a4c2e18ce298590436206666beac36b022d..f1cfa140bcc7babd272e9febc89a85635140e366 100644 (file)
@@ -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,17 +267,28 @@ 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;
+
+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);
+}
 
-/// 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);
+  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);
 }
 
 #define ENABLE_BASE_OPERATORS_ON(T)                                         \
@@ -326,6 +337,8 @@ inline Score operator/(Score s, int i) {
   return make_score(mg_value(s) / i, eg_value(s) / i);
 }
 
+CACHE_LINE_ALIGNMENT
+
 extern Value PieceValue[PHASE_NB][PIECE_NB];
 
 struct ExtMove {