1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 16:53:09 +00:00
Commit graph

3692 commits

Author SHA1 Message Date
Marco Costalba
d3d26a94b3 Improve spinlock implementation
Calling lock.test_and_set() in a tight loop creates expensive
memory synchronizations among processors and penalize other
running threads. So syncronize only only once at the beginning
with fetch_sub() and then loop on a simple load() that puts much
less pressure on the system.

Reported about 2-3% speed up on various systems.

Patch by Ronald de Man.

No functional change.
2015-02-23 19:48:46 +01:00
Marco Costalba
38112060dc Use spinlock instead of mutex for Threads and SplitPoint
It is reported to be defenitly faster with increasing
number of threads, we go from a +3.5% with 4 threads
to a +15% with 16 threads.

The only drawback is that now when testing with more
threads than physical available cores, the speed slows
down to a crawl. This is expected and was similar at what
we had setting the old sleepingThreads to false.

No functional change.
2015-02-23 13:47:07 +01:00
Marco Costalba
775f8239d3 Introduce Spinlock class
Initialization is more complex than what I'd like due
to MSVC compatibility that for some reason does not like:

std::atomic_flag lock = ATOMIC_FLAG_INIT;

No functional change.
2015-02-23 13:37:46 +01:00
Marco Costalba
098f645d26 Sync with master
bench: 8253813
2015-02-23 13:36:15 +01:00
Marco Costalba
29ff925fd8 Fix build under OS X
Reported by Vince Negri

No functional change.
2015-02-22 16:33:24 +01:00
Marco Costalba
8d16111ffd Sync with master
bench: 8253813
2015-02-22 14:20:23 +01:00
Marco Costalba
e2226cbb20 Use only 'level' as late join metric
It seems other metric are useless, this allow us
to simplify the code and to prune useless stuff.

STC 20K games 4 threads
ELO: -0.76 +-2.8 (95%) LOS: 29.9%
Total: 20000 W: 3477 L: 3521 D: 13002

STC 10K games 16 threads
ELO: 1.36 +-3.9 (95%) LOS: 75.0%
Total: 10000 W: 1690 L: 1651 D: 6659

bench: 8253813
2015-02-22 12:59:34 +01:00
Marco Costalba
5fd5453e59 Further refine SMP code
Backported from C++11 branch:

https://github.com/official-stockfish/Stockfish/commit/7ff965eebfbc17d2b
https://github.com/official-stockfish/Stockfish/commit/e74c2df907d5336d3d2b

Fully verified it is equivalent to master (see log msg
of individual commits for details).

No functional change.
2015-02-21 11:33:03 +01:00
Marco Costalba
e74c2df907 Use sp->master instead of bestThread
Verified with:

dbg_hit_on(th != sp->master);

It is 100% equivalent on more than 200K hits.

No functional change.
2015-02-21 10:40:59 +01:00
Stéphane Nicolet
41ccc885ec Fix comment for kingAdjacentZoneAttacksCount
The comment for kingAdjacentZoneAttacksCount[] was bogus, using
reversed semantics for color.

No functional change

Resolves #262
2015-02-20 19:59:26 +00:00
snicolet
2f46592736 Mobile phalanxes
Try to create mobile phalanxes

STC:
LLR: 2.97 (-2.94,2.94) [-1.50,4.50]
Total: 52393 W: 10912 L: 10656 D: 30825

LTC:
LLR: 2.96 (-2.94,2.94) [0.00,6.00]
Total: 30398 W: 5315 L: 5063 D: 20020

Bench: 8253813

Resolves #261
2015-02-20 19:56:57 +00:00
Marco Costalba
7ff965eebf Improve comments in SMP code
No functional change.
2015-02-20 12:38:54 +01:00
Marco Costalba
a6f873cd8d Use range-based-for in late join
No functional change.
2015-02-20 10:50:47 +01:00
Marco Costalba
40548c9153 Sync with master
bench: 7911944
2015-02-20 10:37:29 +01:00
Marco Costalba
667f350737 Clarify we don't late join with only 2 threads
Thanks to Gary for pointing this out.

No functional change.
2015-02-19 23:12:59 +01:00
Marco Costalba
950c8436ed Use size_t consistently across thread code
No functional change.
2015-02-19 10:43:28 +01:00
Marco Costalba
8d47caa16e Retire redundant sp->slavesCount field
It should be used slavesMask.count() instead.

Verified 100% equivalent when sp->allSlavesSearching:

dbg_hit_on(sp->allSlavesSearching, sp->slavesCount != sp->slavesMask.count());

No functional change.
2015-02-19 10:36:15 +01:00
Marco Costalba
b9d4e6f7fd Fix a warning under MSVC
Assignment of size_t to int.

No functional change.
2015-02-19 10:18:24 +01:00
Marco Costalba
193a7ae35b Add a couple of asserts to late join
Document and clarify that we cannot rejoin on ourselves
and that we never late join if we are master and all
slaves have finished, inded in this case we exit idle_loop.

No functional change.
2015-02-19 10:08:29 +01:00
Marco Costalba
4f906a2589 Remove useless condition in late join
In case of Threads.size() == 2 we have that sp->allSlavesSearching
is always false (because we have finished our search), bestSp is
always NULL and we never late join, so there is no need to special
case here.

Tested with dbg_hit_on(sp && sp->allSlavesSearching) and
verified it never fires.

No functional change.
2015-02-19 09:53:39 +01:00
Marco Costalba
dccaa145d2 Compute SplitPoint::spLevel on the fly
And retire a redundant field. This is important also
from a concept point of view becuase we want to keep
SMP structures as simple as possible with the only
strictly necessary data.

Verified with

dbg_hit_on(sp->spLevel != level)

that the values are 100% the same out of more 50K samples.

No functional change.
2015-02-18 21:50:35 +01:00
Marco Costalba
6656ed8904 Simplify attackUnits formula
Use '/ 8' instead of '* 31 / 256'

Passed STC
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 55077 W: 10999 L: 10940 D: 33138

And LTC
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 14751 W: 2530 L: 2400 D: 9821

bench: 7911944
2015-02-17 08:23:35 +01:00
Joona Kiiski
d65f75c153 Improve smp performance for high number of threads
Balance threads between split points.

There are huge differences between different machines and autopurging makes it very difficult to measure the improvement in fishtest, but the following was recorded for 16 threads at 15+0.05:

    For Bravone (1000 games): 0 ELO
    For Glinscott (1000 games): +20 ELO
    For bKingUs (1000 games): +50 ELO
    For fastGM (1500 games): +50 ELO

The change was regression for no one, and a big improvement for some, so it should be fine to commit it.
Also for 8 threads at 15+0.05 we measured a statistically significant improvement:
ELO: 6.19 +-3.9 (95%) LOS: 99.9%
Total: 10325 W: 1824 L: 1640 D: 6861

Finally it was verified that there was no (significant) regression for

4 threads:
ELO: 0.09 +-2.8 (95%) LOS: 52.4%
Total: 19908 W: 3422 L: 3417 D: 13069

2 threads:
ELO: 0.38 +-3.0 (95%) LOS: 60.0%
Total: 19044 W: 3480 L: 3459 D: 12105

1 thread:
ELO: -1.27 +-2.1 (95%) LOS: 12.3%
Total: 40000 W: 7829 L: 7975 D: 24196

Resolves #258
2015-02-16 20:36:13 +00:00
lucasart
f8f5dcbb68 Compute checkers from scratch
This micro-optimization only complicates the code and provides no benefit.
Removing it is even a speedup on my machine (i7-3770k, linux, gcc 4.9.1):

stat        test     master    diff
mean   2,403,118  2,390,904  12,214
stdev     12,043     10,620   3,677

speedup       0.51%
P(speedup>0) 100.0%

No functional change.
2015-02-16 09:34:26 +08:00
Marco Costalba
686b45e121 Retire one do_move() overload
After Lucas patch it is almost useless.

No functional change.
2015-02-15 12:23:03 +01:00
lucasart
dc13004283 Compute checkers from scratch
This micro-optimization only complicates the code and provides no benefit.
Removing it is even a speedup on my machine (i7-3770k, linux, gcc 4.9.1):

stat        test     master    diff
mean   2,403,118  2,390,904  12,214
stdev     12,043     10,620   3,677

speedup       0.51%
P(speedup>0) 100.0%

No functional change.
2015-02-15 12:11:05 +01:00
Marco Costalba
901bfb1f55 Revert "Delayed killers checking"
It seems a slowdown when run with fishbench.

No functional change.
2015-02-15 11:32:53 +01:00
Marco Costalba
20a5c07472 Further simplify KingDanger init
And remove a tale whitespace while there.

No functional change.
2015-02-14 15:56:54 +01:00
Marco Costalba
e38eb2302d Further simplify KingDanger init
And remove a tale whitespace while there.

No functional change.
2015-02-14 15:55:11 +01:00
Marco Costalba
0af24a1445 Sync with master
Bench: 7369224
2015-02-14 15:30:16 +01:00
snicolet
a8f9c7a790 Small bonus for all safe pawn pushes
Pawn flexibility: add a small bonus for all safe pawn pushes

STC:
LLR: 2.70 (-2.94,2.94) [-1.50,4.50]
Total: 18233 W: 3705 L: 3557 D: 10971

LTC:
LLR: 2.97 (-2.94,2.94) [0.00,6.00]
Total: 17684 W: 3042 L: 2854 D: 11788

Bench: 7369224

Resolves #253
2015-02-13 21:33:00 +00:00
Marco Costalba
c0a80afe89 Reformat tracing functions
No functional change.
2015-02-13 11:54:46 +01:00
hxim
44a571c1c7 Fix KingDanger[] array initialization
Use integer arithmetic instead of floating point arithmetic.
Floating point arithmetic was causing different results for some 32-bit compiles

No functional change

Resolves #249
Resolves #250
2015-02-09 22:02:35 +00:00
Marco Costalba
ce8ac7997c Sync with master
bench: 7699138
2015-02-08 21:32:14 +01:00
Joona Kiiski
e118570038 Pawn Center Bind Bonus
Bonus for two pawns controlling the same central square

STC:

LLR: 3.14 (-2.94,2.94) [-1.50,4.50]
Total: 15974 W: 3291 L: 3133 D: 9550

LTC:

LLR: 3.24 (-2.94,2.94) [0.00,6.00]
Total: 10449 W: 1837 L: 1674 D: 6938

Idea from Lyudmil Tsvetkov.

Bench: 7699138

Resolves #248
2015-02-08 19:28:01 +00:00
Marco Costalba
8f10f6c9cd Shuffle put_piece() and friends signatures
It is more consistent with the others member functions.

No functional change.
2015-02-08 18:17:08 +01:00
Marco Costalba
3184852bdc Small tweaks in do_move and friends
Also remove useless StateCopySize64 optimization:
compiler uses SSE movups instruction anyhow and
does not need this trick (verified with fishbench).

No functional change.
2015-02-08 13:09:29 +01:00
Marco Costalba
99c9cae586 Avoid casting to char* in prefetch()
Funny enough, gcc __builtin_prefetch() expects
already a void*, instead Windows's _mm_prefetch()
requires a char*.

The patch allows to remove ugly casts from caller
sites.

No functional change.
2015-02-07 19:13:41 +01:00
Marco Costalba
152a4dc5cd Rewrite pos_is_ok()
No functional change.
2015-02-07 15:02:28 +01:00
Marco Costalba
47a0768102 Micro-optimize SEE
Results for 10 tests for each version (gcc 4.8.3 on mingw):

            Base      Test      Diff
    Mean    1502447   1507917   -5470
    StDev   3119      1364      4153

p-value: 0,906
speedup: 0,004

Results for 10 tests for each version (MSVC 2013):

            Base      Test      Diff
    Mean    1400899   1403713   -2814
    StDev   1273      2804      2700

p-value: 0,851
speedup: 0,002

No functional change.
2015-02-07 12:21:39 +01:00
Marco Costalba
170bdf40cd Rename dbg_hit_on_c() to dbg_hit_on()
Use an overload instead of a new named function.

I have found this handier and easier when adding
some quick debug code.

No functional change.
2015-02-07 11:18:06 +01:00
Marco Costalba
8b0fee9998 Rename dbg_hit_on_c() to dbg_hit_on()
Use an overload instead of a new named function.

I have found this handier and easier when adding
some quick debug code.

No functional change.
2015-02-07 11:15:38 +01:00
Marco Costalba
1277a42823 Sync with master
bench: 7696257
2015-02-07 10:32:28 +01:00
lucasart
35aa21c1fe Removes useless templates, some of which lead to code duplication: is_K*() functions.
No functional change

Resolves #245
2015-02-07 09:12:04 +00:00
Stefan Geschwentner
18b0809639 Add bonus for pawn attack threats
Latent pawn attacks: Add a bonus to safe pawn pushes which attacks an
enemy piece.  Based on an idea of Lyudmil Tsvetkov.

STC:
LLR: 2.95 (-2.94,2.94) [-1.50,4.50]
Total: 7925 W: 1666 L: 1537 D: 4722

LTC:
LLR: 2.95 (-2.94,2.94) [0.00,6.00]
Total: 40109 W: 6841 L: 6546 D: 26722

Bench: 7696257

Resolves #240
2015-02-03 11:19:33 +08:00
mstembera
f4136c5434 Profile build options
I went through all the individual compile options that differ between
-fprofile-generate/-fprofile-use  and  -fprofile-arcs/-fbranch-probabilities
and distilled the speed difference down to only turning off
-fno-peel-loops and -fno-tracer.  Using this we still get the full speedup
(maybe a bit more because other optimizations stay on) and it's also much cleaner
because we can get rid of the "@rm -f ucioption.gc*" hack for all versions of gcc.

No functional change.

Resolves #237
2015-02-03 11:09:37 +08:00
NicklasPersson
ddccb5355c Improved King Safety values
From an SPSA-session on king safety.

STC:
ELO: 3.21 +-2.1 (95%) LOS: 99.8%
Total: 40000 W: 8181 L: 7812 D: 24007

LTC:
LLR: 2.95 (-2.94,2.94) [0.00,4.00]
Total: 47765 W: 8091 L: 7785 D: 31889

Bench: 8589262

Resolves #241
2015-02-03 04:00:52 +08:00
Marco Costalba
1c7a727795 Use move assignment in movegen.h
No functional change and same speed (tested with perft)
2015-02-01 16:42:31 +01:00
Marco Costalba
e56e5045dd Allow to assign a Move to an ExtMove
After defining ExtMove::operator Move(), this is a
natural extension.

No fnctional change.
2015-02-01 13:31:49 +01:00
Marco Costalba
20d6a8e57f Delay checking for duplicated killer moves
Follow the usual approach to delay computation
as far as possible, in case an earlier killer
cut-offs we avoid to do useless work.

This also greatly simplifies the code.

No functional change.
2015-02-01 13:17:42 +01:00