Skip to content

Commit

Permalink
Simplify and optimize value extractors
Browse files Browse the repository at this point in the history
Speed up results by Joona:

gcc-4.7 (1.5%)
gcc-4.8 (0.5%)
gcc-4.9 (1.0%)

Speed up results by mstembera:

gcc 474
p-value: 0.719

gcc 482
p-value: 1

gcc 492
p-value: 0.859

No functional change

Resolves #211
  • Loading branch information
mstembera authored and zamar committed Jan 16, 2015
1 parent ab27635 commit 58fdb84
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/types.h
Expand Up @@ -273,11 +273,15 @@ inline Score make_score(int mg, int eg) {
/// 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);

union { uint16_t u; int16_t s; } mg = { uint16_t(unsigned(s + 0x8000) >> 16) };
return Value(mg.s);
}

inline Value eg_value(Score s) {
return Value((int)(unsigned(s) & 0x7FFFU) - (int)(unsigned(s) & 0x8000U));

union { uint16_t u; int16_t s; } eg = { uint16_t(unsigned(s)) };
return Value(eg.s);
}

#define ENABLE_BASE_OPERATORS_ON(T) \
Expand Down

0 comments on commit 58fdb84

Please sign in to comment.