Introduce serialization of accesses to std::cout

When many threds concurrently print you need to serialize
the access to std::cout to avoid output lines are intermixed
with the contents of each thread.

This is not strictly needed at the moment because
only main thread prints out, although some ad-hoc
test could trigger UCI::loop() printing while searching.

Anyhow we want to lift this pretty avoidable constrain
also as a prerequisite for future work.

This patch just introduces the support, next one will enable
the serialization.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
Convert to sync_cout and sync_endl

Serialize access to std::cout all over the code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
Terminate threads before to exit main()

It is very difficult and risky to assure
that a running thread doesn't access a global
variable. This is currently true, but could
change in the future and we don't want to rely
on code that works 'by accident'. The threads
are still running when ThreadPool destructor is
called (after main() returns) and this could
lead to crashes if a thread accesses a global
that has been already freed. The solution is to
use an exit() function and call it while we are
still in main(), ensuring global variables are
still alive at threads termination time.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
Don't need to memset HashTable

Default c'tor Entry() already initializes
to zero all its POD members.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
Retire Time::restart()

Simplify API.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
Slightly simplify SEE

Some renaming and small code reshuffle.

No fuctional change.
Unroll least valuable attacker loop in SEE

This allows to reduce the scanning for new X-ray attacks
according to the capturing piece type.

It seems to be just a very small speed increase in MSVC 64
bit and gcc 32 bit, I guess cache issues value more than some
instruction less to execute (as usual).

No functional change.
Greatly speed up SEE

Simply reshuffling the code inverting the condition in next_attacker()
yields a miraculous speed up of more than 3% under gcc!

On my laptop a bench run goes from 320Knps to 330Knps

No functional change.
Rename current_time() to now()

Follow C++11 naming conventions.

No functional change.
Get rid of struct Time

We just need the milliseconds of current system
time for our needs. This allows to simplify the
API.

No functional change.
Simplify Option c'tor

No functional change.
Revert "Simplify Option c'tor"

std::to_string() is C++11 material, not c++03.

So revert the patch.
Enable link time optimization only when optimizing

Because it is quite slow, skip it when 'optimize' flag is 'no'

No functional change.
Rename *last to *end

It is a more correct name because it points past the
last move of the list.

No functional change.
Simplify generate_castle()

Skipping the calls to std::min(), std::man() we get
even a nice speed-up on perft.

No functional change.
Remove redundancy in move generation

Introduce generate_all_moves() and remove a good
bunch of redundant code.

No functional change.
Speed-up generate<LEGAL>

The trick here is to check for legality only in the
(rare) cases we have pinned pieces or a king move
or an en-passant.

This trick is able to increase the speed of perft
of more then 20%!

No functional change.
Fix MSVC 2012 64bits warnings

Reported by Rein.

No functional change.
Don't exit earlier from aspiration window loop

Currently we exit the loop when

abs(bestValue) >= VALUE_KNOWN_WIN

but there is no logical reason for this. It seems more
natural to re-search again with full open window.

This has practically no impact in most cases, we have a
'no functional change' running 'bench' command.
Fix compile with Intel 13.0

It seems Intel is unable to properly workout templates with 'static'
storage specifier.

Workaround using an anonymous namespace instead.

No functional change.