mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
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.
This commit is contained in:
parent
323a006666
commit
69ac45d903
1 changed files with 6 additions and 17 deletions
23
src/types.h
23
src/types.h
|
@ -267,28 +267,17 @@ enum Score {
|
||||||
SCORE_ENSURE_INTEGER_SIZE_N = INT_MIN
|
SCORE_ENSURE_INTEGER_SIZE_N = INT_MIN
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef union {
|
inline Score make_score(int mg, int eg) { return Score((mg << 16) + eg); }
|
||||||
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) {
|
inline Value mg_value(Score s) {
|
||||||
ScoreView v;
|
return Value(((s + 0x8000) & ~0xffff) / 0x10000);
|
||||||
v.full = s;
|
|
||||||
return Value(v.half.mg + (uint16_t(v.half.eg) >> 15));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value eg_value(Score s) {
|
inline Value eg_value(Score s) {
|
||||||
ScoreView v;
|
return Value((int)(unsigned(s) & 0x7FFFU) - (int)(unsigned(s) & 0x8000U));
|
||||||
v.full = s;
|
|
||||||
return Value(v.half.eg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ENABLE_BASE_OPERATORS_ON(T) \
|
#define ENABLE_BASE_OPERATORS_ON(T) \
|
||||||
|
|
Loading…
Add table
Reference in a new issue