Commit graph

2505 commits

Author SHA1 Message Date
Marco Costalba 0049d3f337 Reduce stack usage
Shrink dimensions of the biggest stack consumers arrays.
In particular movesSearched[] can be safely shrinked
without any impact on strenght or risk of crashing.
Also MAX_PLY can be reverted to 100 with almost no impact
so to limit search recursion and hence stack allocation.

A different case is for MAX_MOVES (used by Movepicker's
moves[]), because we know that do exsist some artificial
position with about 220 legal moves, so in those cases SF
will crash. Anyhow these cases are never found in games.
An open risk remains perft, especially run above handcrafted
positions.

This patch originates from a report by Daylen that found
SF crashing on his Mac OS X 10.7.3 while in deep analysys
on the following position:

8/3Q1pk1/5p2/4r3/5K2/8/8/8 w - - 0 1

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-08 08:46:04 +01:00
Marco Costalba e0cae4bef8 Fix 'bench' for Chess960 case
Now a fen file with Chess960 positions is
correctly parsed. But it is mandatory to set
"UCI_Chess960" option _before_ to call bench.

Note that this was not needed/possible before
adding the possibility to call 'bench' from
command prompt.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-07 14:07:30 +01:00
Marco Costalba 9546b79e20 Use bench to implement UI 'perft' command
Now that we can call bench on current position
we can directly use it to perform our perft.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-07 13:45:53 +01:00
Marco Costalba cc04a745e2 Teach 'bench' to run current position
Now that we can call bench from command prompt
has a sense to teach bench to run the current
set position. To do this is enough to call bench
with 'current' as fen source parameter.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-07 12:08:34 +01:00
Marco Costalba ce5b972736 Don't need to wait after a "ponderhit"
It is enough to wake up main thread. This is
a better fix than d033d5e06a.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-07 11:47:37 +01:00
Marco Costalba f30f384757 Revert "Penalty for undefended rook"
After extensive test Gary says:

"So, after 16k games at 10"+1" on an i7, the undefended rook test
looks to be not good (albeit by a very small margin).
3063 - 3093 - 9844 (-1).

I doubt that is causing the regression, but even so, it looks like
it's not worth keeping, and we can go back to the simpler undefended
minors check."

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-07 11:34:22 +01:00
Marco Costalba 676b2c8435 Replace Position::copy()
With assignment operator. And fix Position::flip().

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-06 19:42:45 +01:00
Marco Costalba c2fc80e5d1 Revert thread_local stuff
Unfortunatly accessing thread local variable
is much slower than object data (see previous
patch log msg), so we have to revert to old code
to avoid speed regression.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-06 18:47:55 +01:00
Marco Costalba b1f57e92ce Use thread_local compiler specifics
Much faster then pthread_getspecific() but still a
speed regression against the original code.

Following are the nps on a bench:

Position
454165
454838
455433

tls
441046
442767
442767

ms (Win)
450521
447510
451105

ms (pthread)
422115
422115
424276

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-06 18:03:15 +01:00
Marco Costalba bed4075580 Fix a (theoretical) race leading to a crash
After we release the SplitPoint lock the master, suppose
is main thread, can safely return and if a "quit" command
is pending, main thread exits and associated Thread object
is freed. So when we access master->is_searching a crash
occurs.

I have never found such a race that is of course very rare
becuase assumes that from lock releasing we go to sleep for
a time long enough for the main thread to end the search and
return. But you can never know, and anyhow a race is a race.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-06 15:30:41 +01:00
Marco Costalba 5a2d525048 Teach UI thread to use main thread resources
So to avoid a crash when setting the moves in
UCI "position startpos moves ...." command.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-06 15:05:52 +01:00
Marco Costalba e1919384a2 Don't store Thread info in Position
But use the newly introduced local storage
for this. A good code semplification and also
the correct way to go.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-06 14:36:45 +01:00
Marco Costalba 699f700162 Introduce thread local storage
Use thread local storage to store a pointer to the thread we
are running on. This will allow to remove thread info from
Position class.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-06 14:36:39 +01:00
Marco Costalba 797c960d20 Rewrite pop_1st_bit() to be endian independent
With this change sources are fully endianess
independent, so we can simplify the Makefile.

Somewhat surprisingly we don't have any speed
regression !

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-06 12:38:27 +01:00
Marco Costalba 673bc5526f Use a Thread instead of an array index
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-04 12:12:08 +01:00
Marco Costalba 0439a79566 Big Position renaming
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-04 07:35:49 +01:00
Marco Costalba 37fa8adc2b Micro-optimize last_1() for 32bits
Verified assembly it is a bit simpler.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-04 06:54:48 +01:00
Marco Costalba 2f99de0c6c Fix bench with fen files regression
Erroneusly adds default positions to the fens
loaded from external file.

Bug introduced in adb71b8096

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-02 18:40:12 +01:00
Marco Costalba 7a8429d9f1 Simplify Endgames::probe()
With this API change we simplify both function and caller site.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-02 09:58:29 +01:00
Marco Costalba dda0fa1a43 Use polymorphism to resolve map() overloading
The 2 overload functions map() accept a pointer to
EndgameBase<Value> or a pointer to EndgameBase<ScaleFactor>.

Because Endgame<E> is derived from one of them we can
directly use a pointer to this class to resolve the
overload as is needed in Endgames::add().

Also made class Endgames fully parametrized and no more
hardcoded to the types (Value or ScaleFactor) of endgames
stored.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-01 16:16:51 +01:00
Marco Costalba 7eb6a488ad Use a std::vector to store searchMoves
A std::set (that is a rb_tree) seems really
overkill to store at most a handful of moves
and nothing in the common case.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-01 12:45:43 +01:00
Marco Costalba 72641dcaae Retire platform specifics include in misc.cpp
Now that platform.h is included in types.h we
don't need this stuff anymore.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-01 12:00:15 +01:00
Marco Costalba 6e00aa6bae Better document square flipping helpers
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-01 11:30:54 +01:00
Marco Costalba 9bbd27a80f Introduce Bitboards namespace
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-01 11:01:13 +01:00
Marco Costalba adb71b8096 Process 'bench' also from SF prompt
It is possible to start with 'stockfish', then from
command prompt type 'bench' and SF will do what you expect.
Old behaviour is anyhow preserved. As a bonus we can now
start from command line any UCI command understood by
Stockfish. The difference is that after execution of a
command from arguments SF quits, while at the end of the
same command from prompt SF stays in UCI loop.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-01 10:06:30 +01:00
Marco Costalba 32c504076f Use std::vector to implement HashTable
Allows some code semplification and avoids directly
allocation and managing heap memory.

Also the usual renaming while there.

No functional change and no speed regression.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-31 19:07:11 +01:00
Marco Costalba 304deb5e83 Rename Materials and Pawns hash stuff
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-31 11:59:23 +01:00
Marco Costalba d84865eac3 Complete the renaming in Search::LimitsType
This completes the job started with revision
4124c94583.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-31 09:16:09 +01:00
Marco Costalba cc6c745b54 Reset search time as early as possible
In particualr before to wake up main thread that
could take some random time. Until we don't reset
search time we are not able to correctly track
the elapsed search time and this can be dangerous
under extreme time pressure.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-31 10:01:31 +01:00
Marco Costalba d033d5e06a Revert "Call wait_for_search_finished() only when quitting"
We need to wake up main thread if it is sleeping
waiting for stop or ponderhit, so we cannot skip
calling wait_for_search_finished().

Found by Othello1984.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-30 18:58:58 +01:00
Marco Costalba b0b9bb3462 Last touches to pawns shelter code
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-29 21:14:15 +01:00
Marco Costalba 5e18b81e87 Fix an hang when max depth is reached
In this case SF stop searching and goes sleeping
waiting for a stop / ponderhit before to return
best move. So when a "stop" arrives we need to wake
up the main thread again.

Another regression introduced by 3aa471f2a9,
hopefully the last one.

Thanks to Otello1984 to reporting this.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-29 20:04:27 +01:00
Marco Costalba 10e64e0509 Refactor pawns shelter and storm
Renamed stuff and added comments. The aim is to make more
readable, at least by me ;-) , this newly added part of code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-29 00:09:27 +01:00
Marco Costalba 76622342ec Restore MS1BTable[]
Incredible typo from my side!

The 2 tables are completely different, one counts 1s the
other returns the msb position. Even more incredible
the 'stockfish bench' command returns the same number
of nodes!!!

Spotted by Justin Blanchard.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-28 19:11:37 +01:00
Marco Costalba d6e3a40c81 Silently handle "ucinewgame" command
Avoid returning "Unknown command", it seems some
GUI are misguided by this.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-28 18:24:02 +01:00
Marco Costalba 46a50cbf38 Replace MS1BTable[] with BitCount8Bit[]
We already have the necessary infrastructure
in place.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-28 14:08:19 +01:00
Marco Costalba cc2b3ece5c Merge pull request #11 from glinscott/squash
Add more detailed pawn shelter/storm evaluation

After 10670 games at 10"+0.05
Mod vs Orig 2277 - 1941 - 6452 ELO +11 !!!

The first real increase since 2.2.2, congratulations Gary !!!

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-28 07:48:30 +01:00
Marco Costalba 22e294e044 Set do_sleep out of lock protection
Fixes a not so rare crash (once every 100 games)
newly introduced. Unfortunatly I am still not
able to figure out why :-(

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-27 19:27:20 +01:00
Marco Costalba 4124c94583 Use UCI names in Search::LimitsType
There is no need to "invent" different names
from the original UCI parameters.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-27 14:26:58 +01:00
Marco Costalba a56322fde8 Merge pull request #9 from glinscott/master
Penalty for undefended rook

Almost no change at longer TC, but perhaps there
is a tiny increase....

After 17522 games at 10"+0.05
Mod vs Orig 3064 - 2967 - 11491 ELO +2

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-26 19:57:27 +01:00
Marco Costalba 3d0d0237c5 Simplify start_searching() signature
Retire the "sync" behaviour that now is up to
the caller to honour.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-26 18:59:01 +01:00
Marco Costalba d11a529904 Call wait_for_search_finished() only when quitting
When quitting we should avoid RootPosition to be
destroyed while threads are still running, leading
to a crash. In case of a "stop" or "ponderhit"
command there is no need for the UI thread to wait.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-26 18:44:30 +01:00
Marco Costalba 3aa471f2a9 Introduce and use wait_for_search_finished()
Helper function that allows us to simplify
the code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-26 18:22:41 +01:00
Gary Linscott 374c9e6b63 Add more detailed pawn shelter/storm evaluation 2012-03-26 07:52:10 -04:00
Marco Costalba 32d3a07c67 Move ThreadsManager::exit() to d'tor
And add final touches to this long patch series.

All the series has been verified against regression with
20K games at fast TC.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-26 08:18:17 +01:00
Marco Costalba b978eb05dc Fix compile error with gcc
We have a clash with start_fn defined both as a
Thread memeber and as a function pointer type in
pthread_create().

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-25 23:08:35 +01:00
Marco Costalba e4efc8b741 Reset Thread::maxPly before a new search
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-25 16:44:55 +01:00
Marco Costalba 58c2fe391d Fix race in ThreadsManager::sleep()
We cannot set do_sleep flag of main thread before
"bestmove" is sent to GUI, otherwise GUI could send
immediately the next "go" command that triggers
start_thinking() and because do_sleep is set UI
thread resets the flag to launch a new search. But
when shortly after main thread returns to main_loop()
flag is incorrectly reset and main thread goes to sleep
hanging the engine.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-25 16:37:48 +01:00
Gary Linscott dbe5e28eaa Merge remote-tracking branch 'upstream/master' 2012-03-25 10:18:29 -04:00
Marco Costalba c483ffc773 Try to mimic std::thread API
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-25 12:43:19 +01:00