Don't double check for move legality

In case of a RootNode or a SpNode move has
been already checked for legality so we can
skip a redundant check.

Spotted by Frank Genot.

No functional change.
Add eval cache infrastructure

With this patch series we want to introduce a per-thread
evaluation cache to store node evaluation and do not
rely anymore on the TT table for this.

This patch just introduces the infrastructure.

No functional change.
Retire eval optimization from null search

Simplify things preparing for further changes.

bench: 4983282
Don't read eval from TT anymore

Rely fully on eval cache. Note that we still save eval
info to TT, this is not needed at this moment and will be
removed in future patches. We keep it so to have a "non
functional change" patch.

No functional change.
Don't use TT just to save a node evaluation

In search(), after we evalute the position, in case there
isn't any TT entry we create one with just the evaluation
score.

This patches removes that code. The reason becuase the patch
deserves a single commit it is becuase introduces a (very small)
functional change due to the fact that the total number of
TT stores is less now and this slightly alters the TT hits
of our benchmark.

bench: 4983262
Don't save eval score in TT

This patch completes the removal of eval info
in TT table.

No functional change.
Reintroduce eval optimizaion from null search

Now that conversion to eval cache is finished
we can reintroduce this optimization.

bench: 5149248
Increase MAX_THREADS to 64

And document why this is an hard limit. It
seems for some (lucky) people 32 threads
are not enough.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
Merge branch 'eval_cache'

Use an eval cache instead of TT to store node
position evaluations.

It is already an improvment and, because it frees
two TT entry slots, paves the way to extend TT to
store both upper and lower bounds.

After 4855 games, single thread, 15"+0.05
Mod vs Orig 1165 -920 - 2770 ELO +18

bench: 5149248
Update Readme.txt now that we support 64 threads

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
Micro-optimize color_of()

In almost all cases we already know in advance that
color_of() argument is different from NO_PIECE.

So avoid the check for NO_PIECE in color_of() and
test at caller site in the very few places where
this case could occur.

As a nice side effect, this patch fixes a (bogus)
warning under some versions of gcc.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
Store distinct upper and lower bound scores

This is more complex than what I'd like but I
was unable to split in small chunks.

Here we add 2 slots to TTEntry (valueUpper and depthUpper)
so that sizeof(TTEntry) returns to the original 16 bytes
and we can pack exactly 4 entries in a 64 bytes cache line.

Now we save an upper bound score alongside a lower (exact)
score. The idea is to increase TT cut-offs rates becuase
there is now an higher probability for a node to use TT info.

This patch is highly experimental and probably needs further
steps as is hinted by an unrealistic bench number:

bench: 2022385
Ensure valueLower <= valueUpper

In case a TTEntry stores both an upper and a lower bound
ensure that upper bound is not smaller than lower bound.

bench 1813815
Fix comparison with alpha, not beta

This silly bug seems the reason of the unsual bench
value.

bench: 6261882
Merge branch 'eval_cache'

Unusually good result. Defenitly needs further verifications.

After 2160 games at 15"+0.05
Mod vs Orig 486 - 367 - 1307 ELO +19

bench: 6261882
Revert store of distinct upper and lower bounds

Test by Joona prooves the new feature don't value 70 added lines of code.

Grand totals after 10040 games (crashes: 0) for tt_both

master_9edc7 - 6a93488_6a934: 1756 - 1688 - 6596 ELO +2 (+- 2.7)

Confirmed by test of Gary:

After 8680 games:
ELO: 0.80 +- 99%: 9.62 95%: 7.31
LOS: 65.38%
Wins: 1288 Losses: 1268 Draws: 6130

Thanks a lot to both for testing it !!!

bench 5149248
Remove an extra semicolon

No functional change.
Don't need to check for bestValue < beta to split

With rearrangement of fail high code this condition
is no more necessary.

Found by Jörg Oster.

No fuctional change.
Introduce namespace Material

And retire old struct MaterialTable simplifying the code.

No functional change.
Introduce namespace Pawns

And retire old struct PawnTable along the same lines
of previous patch.

No functional change.