]> git.sesse.net Git - stockfish/blobdiff - src/types.h
Pack 3 TT entries in 32 bytes cluster
[stockfish] / src / types.h
index 5fee1786f77564b060afbc3719a3f21f134fa8fb..c3911446e7ab38c0528a27ee941033d182bd82bf 100644 (file)
@@ -218,7 +218,7 @@ enum Depth {
   DEPTH_QS_NO_CHECKS  = -1 * ONE_PLY,
   DEPTH_QS_RECAPTURES = -5 * ONE_PLY,
 
-  DEPTH_NONE = -127 * ONE_PLY
+  DEPTH_NONE = -6 * ONE_PLY
 };
 
 enum Square {
@@ -267,28 +267,17 @@ enum Score {
   SCORE_ENSURE_INTEGER_SIZE_N = INT_MIN
 };
 
-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);
-}
+inline Score make_score(int mg, int eg) { return Score((mg << 16) + eg); }
 
+/// 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) {
-  ScoreView v;
-  v.full = s;
-  return Value(v.half.mg + (uint16_t(v.half.eg) >> 15));
+  return Value(((s + 0x8000) & ~0xffff) / 0x10000);
 }
 
 inline Value eg_value(Score s) {
-  ScoreView v;
-  v.full = s;
-  return Value(v.half.eg);
+  return Value((int)(unsigned(s) & 0x7FFFU) - (int)(unsigned(s) & 0x8000U));
 }
 
 #define ENABLE_BASE_OPERATORS_ON(T)                                         \
@@ -337,6 +326,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 {