From 69ac45d903a809bb80cabf87181958e1311c3fcc Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Thu, 5 Jun 2014 23:55:18 +0200 Subject: [PATCH] Revert "Score extractors" Are broken for big-endian case and I have verified with MSVC 2013 Premium bench is correct and there is no miscompilation, so the main reason to change the original code drops. No functional change. --- src/types.h | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/types.h b/src/types.h index f1cfa140..2aed5486 100644 --- a/src/types.h +++ b/src/types.h @@ -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) \ -- 2.39.2