]> git.sesse.net Git - stockfish/log
stockfish
14 years agoFix a comment in evaluate.cpp
Marco Costalba [Wed, 31 Mar 2010 07:57:48 +0000 (09:57 +0200)]
Fix a comment in evaluate.cpp

Function name is wrong.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoChange poll() signature
Marco Costalba [Wed, 31 Mar 2010 05:43:12 +0000 (06:43 +0100)]
Change poll() signature

After previous patch we don't need any more the call parameters.

This fixes a couple of warnings under MSVC.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRemove several unnecessary UCI options: All king safety options
Tord Romstad [Tue, 30 Mar 2010 13:15:01 +0000 (15:15 +0200)]
Remove several unnecessary UCI options: All king safety options
except "Aggressiveness" and "Cowardice", and "UCI_ShowCurrLine".
No functional change compared to the previous version with the
default settings.

14 years agoRevert LMR reduction based on thinking time
Marco Costalba [Sun, 28 Mar 2010 11:04:41 +0000 (12:04 +0100)]
Revert LMR reduction based on thinking time

After 500 games at 5+0 on my QUAD (3 days) there
is no difference with old version, so probably it
is a feature that doesn't scale with search depth.

So revert for now, perhaps we should readd under a
different form.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSmall comments tweaks in search.cpp
Marco Costalba [Wed, 24 Mar 2010 09:15:00 +0000 (10:15 +0100)]
Small comments tweaks in search.cpp

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSync static null conditions with real one
Marco Costalba [Mon, 22 Mar 2010 07:52:04 +0000 (08:52 +0100)]
Sync static null conditions with real one

Almost no functional change, but it seems more
in line with the meaning of static null pruning.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSilence a couple of warnings
Marco Costalba [Tue, 23 Mar 2010 22:34:21 +0000 (23:34 +0100)]
Silence a couple of warnings

MSVC complains about an implicit conversion from double to int.

Also small comments tweaks.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoVary reduction aggressiveness as a function of thinking time
Joona Kiiski [Sun, 21 Mar 2010 20:44:56 +0000 (22:44 +0200)]
Vary reduction aggressiveness as a function of thinking time

In the beginning use milder reduction and at the end be
more aggressive.

After 1500 games on Joona's QUAD
Mod - Orig: 791 - 720 +16 elo

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoBase work for different reduction schemes
Joona Kiiski [Sun, 21 Mar 2010 20:34:30 +0000 (22:34 +0200)]
Base work for different reduction schemes

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoDo not return unproven mate scores from null move search
Joona Kiiski [Sun, 21 Mar 2010 21:41:50 +0000 (23:41 +0200)]
Do not return unproven mate scores from null move search

Causes very small functional change which is not observable with
our usual set of test positions.

However change is observable fx. with following position:
4k3/3r4/5Q2/6K1/8/8/8/8 w - - 0 1
go depth 24

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUse fail soft in null search
Marco Costalba [Sat, 20 Mar 2010 11:42:23 +0000 (12:42 +0100)]
Use fail soft in null search

If null search fails high return null value instead of beta.

With TT hash there may be a small advantage for fail-soft since
storing slightly better bounds may cause slightly more hash hits.

After 990 games at 1+0
Mod vs Orig +171 =665 -154  +6 ELO

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRemove castleRightsMask[] hack
Marco Costalba [Sat, 20 Mar 2010 10:59:22 +0000 (11:59 +0100)]
Remove castleRightsMask[] hack

Array castleRightsMask[] is not static because it can
be different for different positions, so let it be
a Position member data. This allows to remove tricky
hacks to take in account that although it was defined
static it could change.

Theoretically now copying a position is a bit slower because
we need to copy also an array of 64 integers, but because in
split() we don't copy the position anymore, but just keep the
pointer, the added burden is not mesurable even in MP case.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRetire Position::fast_copy()
Marco Costalba [Sat, 20 Mar 2010 10:45:04 +0000 (11:45 +0100)]
Retire Position::fast_copy()

It is never used and could be tricky, so remove it.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUpdated copyright year to 2010
Marco Costalba [Sat, 20 Mar 2010 10:27:07 +0000 (11:27 +0100)]
Updated copyright year to 2010

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFix POPCNT detection gcc compile error
Marco Costalba [Wed, 17 Mar 2010 17:09:37 +0000 (18:09 +0100)]
Fix POPCNT detection gcc compile error

Also don't use __cpuid() intrinsic for Intel under
Linux because gives wrong results when detecting HT,
use the gcc version instead. Finally clean up the code.

Error was due to changed __cpuid() signature for
gcc compiler.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFix __cpuid() compile error with gcc
Marco Costalba [Wed, 17 Mar 2010 12:22:28 +0000 (13:22 +0100)]
Fix __cpuid() compile error with gcc

Use same __cpuid() signature used under Windows.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoAdd hyper-threading detection
Marco Costalba [Sun, 14 Mar 2010 11:14:09 +0000 (12:14 +0100)]
Add hyper-threading detection

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoMove __cpuid() definition for gcc in types.h
Marco Costalba [Sun, 14 Mar 2010 10:16:25 +0000 (11:16 +0100)]
Move __cpuid() definition for gcc in types.h

This will allow to use the function also for other
purposes then detecting POPCNT.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoIntroduce captured_piece()
Marco Costalba [Mon, 8 Mar 2010 13:57:01 +0000 (14:57 +0100)]
Introduce captured_piece()

It will be used by future patches and also rearranges some
half cooked code that mistakenly ended up in master in the
past.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoReduce increase progression of aspiration window
Marco Costalba [Tue, 9 Mar 2010 14:46:20 +0000 (15:46 +0100)]
Reduce increase progression of aspiration window

Currently, in case of fail high/low we research with
a window increased by 2*AspirationDelta at first
attempt, this patch instead makes the research be
done with an increase of just AspirationDelta size,
in case of a consecutive fail we will widen to
2*AspirationDelta and so on.

After Joona's test:
Orig - Mod: 850 - 890

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUse separated research counters in root_search()
Marco Costalba [Sun, 7 Mar 2010 08:02:34 +0000 (10:02 +0200)]
Use separated research counters in root_search()

One for failing highs and one for failing lows, this
should reduce average window size in case of positions
that fail first high and then low (or the contrary).

After ~2000 games on Joona's quad we have:

Mod - Orig: 1012- 975 (+6 elo)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoGroup time management globals initialization
Marco Costalba [Tue, 9 Mar 2010 13:25:07 +0000 (14:25 +0100)]
Group time management globals initialization

Instead to leave uninitialized or scattered in the code
as is the case for ExtraSearchTime.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoHighlight that alpha and beta could change in root_search()
Marco Costalba [Sat, 6 Mar 2010 17:17:04 +0000 (18:17 +0100)]
Highlight that alpha and beta could change in root_search()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFix a comment and add an assert in root_search()
Marco Costalba [Sat, 6 Mar 2010 16:51:56 +0000 (17:51 +0100)]
Fix a comment and add an assert in root_search()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRetire RootMoveNumber and use FirstRootMove instead
Marco Costalba [Sat, 6 Mar 2010 16:34:36 +0000 (17:34 +0100)]
Retire RootMoveNumber and use FirstRootMove instead

It is more clear why we use that global flag.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSave mateThreat flag in splitPoint and make use of it
Joona Kiiski [Thu, 4 Mar 2010 07:10:06 +0000 (09:10 +0200)]
Save mateThreat flag in splitPoint and make use of it

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoDocument one test result
Joona Kiiski [Thu, 4 Mar 2010 06:52:35 +0000 (08:52 +0200)]
Document one test result

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSynchronize root_search() with other search routines
Joona Kiiski [Wed, 3 Mar 2010 20:00:44 +0000 (22:00 +0200)]
Synchronize root_search() with other search routines

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRemove obsolete code snippet from root_search
Joona Kiiski [Wed, 3 Mar 2010 16:53:46 +0000 (18:53 +0200)]
Remove obsolete code snippet from root_search

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSort again root moves after a fail low
Marco Costalba [Sat, 6 Mar 2010 10:43:31 +0000 (11:43 +0100)]
Sort again root moves after a fail low

Currently we use original sorting after a fail low to
research at wider window. This patch instead sorts the
moves according to the last available move's scores.

Strangely no functional change, but should be.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoAdditional search.cpp cleanup
Marco Costalba [Fri, 5 Mar 2010 10:55:27 +0000 (11:55 +0100)]
Additional search.cpp cleanup

Changed FutilityMarginsMatrix dimensions to be a power of two
so that compiler can produce a faster accessing code.

Introduced print_pv_info() to remove some redundant code in
root_search()

Remaining stuff is triviality and documentation tweaks.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoDestroy all locks before to exit
Marco Costalba [Sun, 28 Feb 2010 11:23:53 +0000 (12:23 +0100)]
Destroy all locks before to exit

And use platform-independent functions
where possible.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoWe don't need lpThreadId parameter in CreateThread()
Marco Costalba [Sun, 28 Feb 2010 10:53:29 +0000 (11:53 +0100)]
We don't need lpThreadId parameter in CreateThread()

Under Windows we use CreateThread() to setup threads and
we pass a pointer to a variable that receives the thread
identifier, but this parameter is optional and we don't
use it, so remove it.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFunction init_thread() should return an integer under Windows
Marco Costalba [Sun, 28 Feb 2010 10:36:40 +0000 (11:36 +0100)]
Function init_thread() should return an integer under Windows

It happens that NULL is 0, but the conventional meaning is of
a zero pointer, so repleace with an explicit 0 integer value.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoTry bad captures before non-captures
Marco Costalba [Sat, 27 Feb 2010 16:09:07 +0000 (17:09 +0100)]
Try bad captures before non-captures

Consider sligtly negative captures as good if at low
depth and far from beta.

After 999 games at 1+0
Mod vs Orig +169 =694 -136  +11 ELO

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRevert previous patch
Marco Costalba [Sat, 27 Feb 2010 16:22:19 +0000 (17:22 +0100)]
Revert previous patch

It raises an assert under Windows, it is not clear why but it
happens that idle_loop() is called with incorrect threadID and
the assert triggered is:

assert(threadID >= 0 && threadID < MAX_THREADS);

So revert the patch for now, but we should understand why it
fails.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoDo not wait for sleeping in init_threads()
Marco Costalba [Sat, 27 Feb 2010 12:26:04 +0000 (13:26 +0100)]
Do not wait for sleeping in init_threads()

We can't do it with full guarantee anyway because
there is always a possible race between the setting of
state to THREAD_SLEEPING and actual sleeping.

So just remove the not perfect code to avoid misunderstandings.
This reflects what we have done in wake_sleeping_threads() in
the previous patch.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRemove an incorrect assert in wake_sleeping_threads()
Marco Costalba [Sat, 27 Feb 2010 11:01:07 +0000 (12:01 +0100)]
Remove an incorrect assert in wake_sleeping_threads()

Currently there is no guarantee that threads are sleeping
when calling wake_sleeping_threads() because put_threads_to_sleep()
returns without waiting for threads to actually sleep.

Assert can be easily triggered calling put_threads_to_sleep() and
wake_sleeping_threads() in a tight loop.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoAdd some commentary
Joona Kiiski [Thu, 25 Feb 2010 17:30:57 +0000 (19:30 +0200)]
Add some commentary

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoClean up common adjustments
Joona Kiiski [Thu, 25 Feb 2010 17:16:12 +0000 (19:16 +0200)]
Clean up common adjustments

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRemove "Threat Depth" ucioption
Joona Kiiski [Thu, 25 Feb 2010 17:05:06 +0000 (19:05 +0200)]
Remove "Threat Depth" ucioption

This option likely has very low meaning for playing strength and style,
so I see no need to keep this configurable

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoCleanup steps 12, 14
Joona Kiiski [Thu, 25 Feb 2010 16:59:16 +0000 (18:59 +0200)]
Cleanup steps 12, 14

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoClean up step 11
Joona Kiiski [Thu, 25 Feb 2010 16:43:47 +0000 (18:43 +0200)]
Clean up step 11

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoClean steps 8 and 9.
Joona Kiiski [Thu, 25 Feb 2010 16:27:27 +0000 (18:27 +0200)]
Clean steps 8 and 9.

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoClean razoring code (step 6)
Joona Kiiski [Thu, 25 Feb 2010 15:50:47 +0000 (17:50 +0200)]
Clean razoring code (step 6)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSynchronize variable listing of 4 different search routines
Joona Kiiski [Thu, 25 Feb 2010 11:52:03 +0000 (13:52 +0200)]
Synchronize variable listing of 4 different search routines

search() is used as a "leading star" and other routines
are modified according to it.

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRemove current line printing in SMP mode
Joona Kiiski [Thu, 25 Feb 2010 10:21:56 +0000 (12:21 +0200)]
Remove current line printing in SMP mode

Was broken and fixing would be too messy.
Now this option is only activated in single thread mode

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSynchronize sp_search() with search() part I
Joona Kiiski [Wed, 24 Feb 2010 15:30:13 +0000 (17:30 +0200)]
Synchronize sp_search() with search() part I

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRename staticValue to refinedValue
Joona Kiiski [Wed, 24 Feb 2010 11:04:44 +0000 (13:04 +0200)]
Rename staticValue to refinedValue

Just to avoid misunderstandings.
True staticValue is available through search stack

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFix repetition detection bug
Joona Kiiski [Wed, 24 Feb 2010 18:13:35 +0000 (20:13 +0200)]
Fix repetition detection bug

Bug spotted by Jouni Uski and fix suggested by Pablo Vazquez

Also add note that we are not always handling fifty move rule correctly

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSynchronize sp_search_pv() with search_pv()
Joona Kiiski [Wed, 24 Feb 2010 15:52:37 +0000 (17:52 +0200)]
Synchronize sp_search_pv() with search_pv()

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSynchronize sp_search() with search() part II
Joona Kiiski [Wed, 24 Feb 2010 15:36:45 +0000 (17:36 +0200)]
Synchronize sp_search() with search() part II

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSimplify locking in splitpoint search
Joona Kiiski [Wed, 24 Feb 2010 14:44:34 +0000 (16:44 +0200)]
Simplify locking in splitpoint search

One rule: Always lock before picking up a move.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSynchronize search_pv() with search take II
Joona Kiiski [Wed, 24 Feb 2010 12:05:31 +0000 (14:05 +0200)]
Synchronize search_pv() with search take II

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSynchronize search_pv() with search take I
Joona Kiiski [Wed, 24 Feb 2010 11:41:22 +0000 (13:41 +0200)]
Synchronize search_pv() with search take I

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSearch code documentation, take III
Joona Kiiski [Wed, 24 Feb 2010 10:55:58 +0000 (12:55 +0200)]
Search code documentation, take III

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSearch code documentation take II
Joona Kiiski [Wed, 24 Feb 2010 10:37:32 +0000 (12:37 +0200)]
Search code documentation take II

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSeparate razoring from null move
Joona Kiiski [Wed, 24 Feb 2010 10:26:36 +0000 (12:26 +0200)]
Separate razoring from null move

I cannot see connection between the two.

Also add one FIXME for illogical behaviour

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSplit search() in independent sections
Joona Kiiski [Wed, 24 Feb 2010 10:19:47 +0000 (12:19 +0200)]
Split search() in independent sections

I don't know if enumerating sections is a good idea,
but for me code is more readable this way

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoAvoid research in case thread has already been asked to stop
Joona Kiiski [Wed, 24 Feb 2010 10:02:39 +0000 (12:02 +0200)]
Avoid research in case thread has already been asked to stop

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoAdd one assert
Joona Kiiski [Tue, 23 Feb 2010 10:07:58 +0000 (12:07 +0200)]
Add one assert

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoDo not wait for threads falling asleep
Joona Kiiski [Tue, 23 Feb 2010 10:05:26 +0000 (12:05 +0200)]
Do not wait for threads falling asleep

I cannot see any reason to do this. Even this is not enough to fix
theoretical race case on Windows which doesn't seem to cause any
problems in practice anyhow

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRemove unnecessary conditions from if-clauses and replace them with asserts
Joona Kiiski [Tue, 23 Feb 2010 10:00:56 +0000 (12:00 +0200)]
Remove unnecessary conditions from if-clauses and replace them with asserts

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFix crash in debug mode
Joona Kiiski [Mon, 22 Feb 2010 13:42:12 +0000 (15:42 +0200)]
Fix crash in debug mode

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFix some races
Joona Kiiski [Mon, 22 Feb 2010 13:15:55 +0000 (15:15 +0200)]
Fix some races

Resurrect extra check for sleeping in POSIX code.
This necessary to prevent ugly races between
thread_broadcast and thread_cond_wait.

After thread has woken up, it marks itself as available.
Another thread must not do this, because of possible race.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFix one assert
Joona Kiiski [Mon, 22 Feb 2010 13:00:30 +0000 (15:00 +0200)]
Fix one assert

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFix compile errors in debug mode
Joona Kiiski [Mon, 22 Feb 2010 12:59:01 +0000 (14:59 +0200)]
Fix compile errors in debug mode

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoDocument struct SplitPoint fields constness
Marco Costalba [Sun, 21 Feb 2010 15:10:19 +0000 (16:10 +0100)]
Document struct SplitPoint fields constness

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoBeta is never changed after an sp_search()
Marco Costalba [Sun, 21 Feb 2010 14:28:27 +0000 (15:28 +0100)]
Beta is never changed after an sp_search()

So we can use a const value instead of a pointer in
split().

Also pass NULL instead of a faked address of alpha in
case split is called from a non-PV node.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSupress make warning on missing .depend file
Marco Costalba [Sun, 21 Feb 2010 14:18:35 +0000 (15:18 +0100)]
Supress make warning on missing .depend file

This is generated by make itself, so the warning
is useless.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFix an icc warning
Marco Costalba [Sun, 21 Feb 2010 14:07:53 +0000 (15:07 +0100)]
Fix an icc warning

remark #1599: declaration hides variable "i" (declared at line 2651)

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoCode style triviality in split()
Marco Costalba [Sun, 21 Feb 2010 13:05:38 +0000 (14:05 +0100)]
Code style triviality in split()

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFix a warning with POPCNT and MSVC
Marco Costalba [Sun, 21 Feb 2010 12:44:36 +0000 (13:44 +0100)]
Fix a warning with POPCNT and MSVC

Intrinsic __popcnt64() returns an unsigned __int64, cast
to an integer and silence the warning.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRevert "Recursive lock"
Marco Costalba [Sat, 20 Feb 2010 22:56:02 +0000 (23:56 +0100)]
Revert "Recursive lock"

Joona says that sp_update_pv() does not pass the split point
boundaries, so there is no risk to corrupt data from another
split point. Also the race on thread_should_stop() is harmless
because of this.

So revert the patch and come back to single lock.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRemove a couple of useless thread_should_stop() calls
Marco Costalba [Sat, 20 Feb 2010 22:48:54 +0000 (23:48 +0100)]
Remove a couple of useless thread_should_stop() calls

We test for it anyway few lines below and even under lock
protection.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRevert small state change optimization in idle_loop()
Marco Costalba [Sat, 20 Feb 2010 17:36:07 +0000 (18:36 +0100)]
Revert small state change optimization in idle_loop()

Joona says:

1. We should not be afraid of "AllThreadsShouldExit" flag.
Because when this is set to true we _must_not_ be searching (= All
splits must have been undone).
And if we are not searching it's impossible that some other thread
could give us work to do. So setting state to THREAD_AVAILABLE
doesn't do any harm. If you want to add check for this, you could do
it like this:

 if (threads[threadID].state == THREAD_WORKISWAITING)
 {
+    assert(!AllThreadsShouldExit)
     threads[threadID].state = THREAD_SEARCHING;

2a. If waitSp->cpus == 0, setting state to THREAD_AVAILABLE makes
no harm either, because helpful master concept dictates that _only_
our own slave can book us. If we don't have any slaves, noone has the
right to book us.

2b. If point (2a) is not correct then your extra check only adds extra race:
In smp code checking for waitSp->cpus > 0 is not enough. It's possible that
our slave immediately exits and another thread
books us as a slave when our state is still
THREAD_AVAILABLE. So instead of adding extra level of security we have
just introduced extra race.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRecursive lock all split point's chain
Marco Costalba [Sat, 20 Feb 2010 17:29:53 +0000 (18:29 +0100)]
Recursive lock all split point's chain

When we found a cut-off then lock all the split point chain,
not only current one to avoid races in case two threads running
on different split points where one is ancestor then the other,
find a beta cut-off at the same time, in this case we want only
one to call sp_update_pv().

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRetire per-thread stopRequest flag
Marco Costalba [Sat, 20 Feb 2010 16:52:09 +0000 (17:52 +0100)]
Retire per-thread stopRequest flag

This is a per split-point request, not per-thread. When we find
a beta cut-off in current thread's split point or in or in some
ancestor of the current split point then threads should stop
immediately the search and return to idle_loop().

The check is done by thread_should_stop() that now looks only
at split point's chain.

No functional change and a good semplification.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUse state instead of flags to track threads
Marco Costalba [Sat, 20 Feb 2010 13:57:26 +0000 (14:57 +0100)]
Use state instead of flags to track threads

This is easier to follow and also reduces the points
where state changes to mainly idle_loop() and split().

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRename THREAD_MAX in MAX_THREADS
Marco Costalba [Sat, 20 Feb 2010 12:38:04 +0000 (13:38 +0100)]
Rename THREAD_MAX in MAX_THREADS

Also rename idle_thread_exists() in available_thread_exists()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSearch negative SEE moves in qsearch in PV
Joona Kiiski [Fri, 12 Feb 2010 08:53:03 +0000 (10:53 +0200)]
Search negative SEE moves in qsearch in PV

After 2704 games on slow single core
mod - orig: 1381 - 1323

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUse zero null move margin when depth < 4 * OnePly
Joona Kiiski [Fri, 12 Feb 2010 14:40:00 +0000 (16:40 +0200)]
Use zero null move margin when depth < 4 * OnePly

This is because when we are below 4 * OnePly, the null move
will directly jump to qsearch and if we are below beta,
our opponent is above beta and will get immediate
stand pat cut off.

So basically this patch is just optimizing away useless
evaluation calls. dbg_hit_on() runs show that this heuristic
is correct >99% of cases. Transposition table probably causes
some inaccurary?

After 1148 games on QUAD
mod-orig: 583 - 565 +5 elo

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFix another setting of a flag out of lock protection
Marco Costalba [Sun, 14 Feb 2010 15:29:28 +0000 (16:29 +0100)]
Fix another setting of a flag out of lock protection

In this case is dangerous because in split() we reset the flag to
false, but if it was set due to a cut-off higher in the tree we
completely miss that and go on with the full search.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRename flag 'stop' in 'stopRequest'
Marco Costalba [Sun, 14 Feb 2010 15:04:53 +0000 (16:04 +0100)]
Rename flag 'stop' in 'stopRequest'

Instead of other flags this is not a state flag, i.e. does
not defines a state for the thread, but a request because
after we raise 'stopRequest' flag the corresponding thread is
not stopped, but continues to run for a while until it returns
from sp_search() in idle_loop.

It is important the name reflects this.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoReset thread flags to a known state before to exit think()
Marco Costalba [Sun, 14 Feb 2010 14:58:46 +0000 (15:58 +0100)]
Reset thread flags to a known state before to exit think()

Among them 'stop' and 'printCurrentLineRequest' could have
random value, so reset to a known state before to leave the
search.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFix 'stop' flag changed out of lock protection
Marco Costalba [Sun, 14 Feb 2010 12:31:05 +0000 (13:31 +0100)]
Fix 'stop' flag changed out of lock protection

This is the first nice effect of previous patch !

Because thread_should_stop() should be declared 'const' we
need to remove the setting of 'stop' flag to true that
turns out to be a bug because thread_should_stop() is called
outside from lock protection while 'stop' flag is a volatile
shared variable so cannot be changed when not in lock.

Note that this bugs fires ONLY when we use more then 2 threads,
so commonly only in a QUAD or OCTAL machine.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoIntroduce ThreadsManager class
Marco Costalba [Sat, 13 Feb 2010 12:38:32 +0000 (13:38 +0100)]
Introduce ThreadsManager class

Main aim of this patch is to consolidate all the thread related stuff
behind a single class interface so to avoid messing with global flags
and having thread code scattered among non-thread related stuff.

Another advantage is that now access to thread's variables is
more controlled, in particular we can differentiate between
read and write accesses by the mean of different interfaces, it
is so simpler to understand how a function is related to threads.

Lastly this rewrite is the base for future code consolidations and
semplifications that are easier now that we have only one thread's
access point.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFix compile error under gcc
Marco Costalba [Sat, 13 Feb 2010 12:40:23 +0000 (13:40 +0100)]
Fix compile error under gcc

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoEnsure function boundaries for threads state changes
Marco Costalba [Sat, 13 Feb 2010 11:39:27 +0000 (12:39 +0100)]
Ensure function boundaries for threads state changes

Ensure threads are sleeping when leaving init_threads() and
the newly introduced put_threads_to_sleep().

Also ensure threads are not sleeping when leaving
wake_sleeping_threads().

As a side effect we now leave think() with all the threads
(but the main one) guaranteed to sleep. So when we enter
again in think(), after the opponent next move, we know
threads must be sleeping.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRename stop_threads() to exit_threads()
Marco Costalba [Sat, 13 Feb 2010 11:07:13 +0000 (12:07 +0100)]
Rename stop_threads() to exit_threads()

More stick to what actually happens.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoBe sure threads are woken in wake_sleeping_threads()
Marco Costalba [Sat, 13 Feb 2010 11:02:34 +0000 (12:02 +0100)]
Be sure threads are woken in wake_sleeping_threads()

Wait inside wake_sleeping_threads() for the threads to be
effectively and reliably woken up.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUse Thread c'tor to properly init the struct
Marco Costalba [Sat, 13 Feb 2010 10:40:55 +0000 (11:40 +0100)]
Use Thread c'tor to properly init the struct

This is what c'tors are for.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoAdd 'sleeping' flag to struct Thread
Marco Costalba [Sat, 13 Feb 2010 10:22:57 +0000 (11:22 +0100)]
Add 'sleeping' flag to struct Thread

Will be used by future patches. Also:

- Renamed Idle in AllThreadsShouldSleep

- Explicitly inited AllThreadsShouldExit and AllThreadsShouldSleep
  in init_thread() instead of use an anonymous global initialization.

- Rewritten idle_loop() while condition to avoid a 'break' statement

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoAllow build on HP-UX 11.X
Marco Costalba [Fri, 12 Feb 2010 05:49:16 +0000 (06:49 +0100)]
Allow build on HP-UX 11.X

Patch from Richard Lloyd (slightly edited from me), following the list
of changes as described by the author:

src/Makefile:
- Added PREFIX and BINDIR for the install: rule.
- Added a "make hpux" line to the help: rule.
- Added "make test"/"make check" rule that runs the $(PGOBENCH) command.
- "make clean" now additionally removes core and bench.txt.
- Added an hpux: rule.
- Added an install: rule to mkdir $(BINDIR), copy $(EXE) to $(BINDIR) and
 then strip it.
- "make strip" now ensures that $(EXE) is built first before trying to
 strip it.
- Hide errors and output from the g++ command used by the .depend: rule and
 then touch .depend in case g++ isn't available.
- Hide errors from the "include .depend" in case .depend doesn't exist
 (e.g. directly after a "make clean").

src/book.cpp and src/book.h:
- HP-UX's aCC really didn't like the const keywords used for the
 Book::file_name() definitions, so they were removed. I checked that this
 didn't affect a Linux build and it was still fine.

src/misc.cpp:
- HP-UX uses <sys/pstat.h> and pstat_getdynamic() to determine the number of
 CPU cores, so added conditional code for that (if pstat_getdynamic() fails,
 set the number of cores to 1).

src/tt.cpp:
- <xmmintrin.h> and _mm_prefetch() seem highly specific to the Intel x86(_64)
 and gcc platforms - neither exist in HP-UX, so conditionally avoid that
 code in HP-UX's case. Perhaps some sort of define is needed here
 such as -DHAS_MM_PREFETCH that could be #ifdef'ed for instead?

Even after these changes, it's more convenient for HP-UX users to edit the
default: rule in the Makefile to run "$(MAKE) hpux" before they build
stockfish, but that's not a big deal if they're warned about that first (the
same applies to all other builds other than the standard "$(MAKE) gcc" one).

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFix a couple of new MSVC 2010 warnings
Marco Costalba [Wed, 10 Feb 2010 20:27:44 +0000 (21:27 +0100)]
Fix a couple of new MSVC 2010 warnings

Compiler complains because in Book we have a d'tor but not
copy c'tor and assignement operator (warning C4511 and C4512),
note that after adding them (just declared) you now need also
default c'tor !

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRetire EvalInfo* in SearchStack
Marco Costalba [Mon, 8 Feb 2010 09:48:58 +0000 (10:48 +0100)]
Retire EvalInfo* in SearchStack

It is an hidden bug waiting to fire. The main problem is
that ss[ply] is overwritten by search() and qsearch() called
from IID and razoring, so that we cannot hold a pointer to a
local EvalInfo variable.

For instance if we go razoring then we overwrite the pointer
with the address of a variable local to qsearch(), when we return
from qsearch() variable goes out of scope and now ss[ply].evalInfo
holds a stale pointer !

Because we are not looking for troubles we go through the
safe route and we remove it entirely.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSmall code style triviality
Marco Costalba [Sun, 7 Feb 2010 12:19:10 +0000 (13:19 +0100)]
Small code style triviality

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoImplement init_search()
Joona Kiiski [Sun, 7 Feb 2010 11:15:39 +0000 (13:15 +0200)]
Implement init_search()

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoDocument lookup tables
Joona Kiiski [Sun, 7 Feb 2010 08:53:15 +0000 (10:53 +0200)]
Document lookup tables

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoImplement futility move count array
Joona Kiiski [Sun, 7 Feb 2010 08:42:40 +0000 (10:42 +0200)]
Implement futility move count array

No functional change

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