Commit graph

2505 commits

Author SHA1 Message Date
Marco Costalba 5900ab76a0 Rename current_time() to now()
Follow C++11 naming conventions.

No functional change.
2012-09-02 17:04:22 +02:00
Marco Costalba e6d8e74152 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.
2012-09-02 00:27:53 +02:00
Marco Costalba 9cdca7516c 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.
2012-09-01 18:57:38 +02:00
Marco Costalba 6436e75858 Slightly simplify SEE
Some renaming and small code reshuffle.

No fuctional change.
2012-09-01 15:42:04 +02:00
Marco Costalba 831f91b859 Retire Time::restart()
Simplify API.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-31 19:47:07 +02:00
Marco Costalba 1258c7aabe 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>
2012-08-31 19:47:00 +02:00
Marco Costalba 8dcb4bc3cc 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>
2012-08-29 19:11:44 +02:00
Marco Costalba 0a003d3ba1 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>
2012-08-29 19:11:44 +02:00
Marco Costalba 92e759a676 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>
2012-08-29 19:11:31 +02:00
Marco Costalba 3df2c01b57 Correctly handle handover of setup states
Before the search we setup the starting position doing all the
moves (sent by GUI) from start position to the position just
before to start searching.

To do this we use a set of StateInfo records used by each
do_move() call. These records shall be kept valid during all
the search because repetition draw detection uses them to back
track all the earlier positions keys. The problem is that, while
searching, the GUI could send another 'position' command, this
calls set_position() that clears the states! Of course a crash
follows shortly.

Before searching all the relevant parameters are copied in
start_searching() just for this reason: to fully detach data
accessed during the search from the UCI protocol handling.
So the natural solution would be to copy also the setup states.
Unfortunatly this approach does not work because StateInfo
contains a pointer to the previous record, so naively copying and
then freeing the original memory leads to a crash.

That's why we use two std::auto_ptr (one belonging to UCI and another
to Search) to safely transfer ownership of the StateInfo records to
the search, after we have setup the root position.

As a nice side-effect all the possible memory leaks are magically
sorted out for us by std::auto_ptr semantic.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-27 19:17:02 +02:00
Marco Costalba 8991a6f005 Use std::deque to store setup states 2012-08-26 18:07:54 +02:00
Marco Costalba 16f380e5c1 Document PolyGlotRandoms[] offsets
Should be more clear from where the 'magic' numbers
come from.

Also bit of reformat while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-25 20:00:07 +01:00
Marco Costalba cbd7ce468c Explicitly use threads.size()
Instead of just size(). Although code is longer,
should be more immediate to understand when reading.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-24 13:41:29 +01:00
Marco Costalba b6883c872d Introduce struct Mutex and ConditionVariable
To mimics C++11 std::mutex and std::condition_variable,
also rename locks and condition variables to be more
uniform across the classes.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-24 12:30:36 +01:00
Marco Costalba fde0b9e701 Slightly microptimize SEE
Reduce of one instruction. It seems a tad faster on
the profiler now. Very slightly but anyhow it is a
code semplification.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-24 09:30:50 +01:00
Marco Costalba 7a2825053e Use size_t as operator[] argument type
This better mimics std::vector::operator[] and
fixes a warning with MSVC 64bit.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-22 11:44:43 +01:00
Marco Costalba 4e619a13d6 Merge generate_direct_checks() in generate_moves()
Further reduce redundancy in move generation.
Veirifed no speed regression on MSVC, Clang and gcc.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-22 11:34:52 +01:00
Marco Costalba 0de9257610 Streamline generate_moves()
Greatly simplify these very performace critical functions.
Amazingly we don't have any speed regression actually under
MSVC we have the same assembly for generate_moves() !

In generate_direct_checks() 'target' is calculated only
once being a loop invariant.

On Clang there is even a slight speed up.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-22 09:23:03 +01:00
Marco Costalba b84af67f4c Reformat piece values arrays
And rename stuff while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-20 19:17:58 +01:00
Marco Costalba 7c8b7222f5 Move zobrist keys out of Position
Are used by Position but do not belong to that class,
there is only one instance of them (that's why were
defined as static), so move to a proper namespace instead.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-20 18:24:06 +01:00
Marco Costalba ec9038b7b4 Retire copy c'tor from class Position
Not needed.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-20 14:44:30 +01:00
Marco Costalba ab65d3fd0e Prefer a reference to a pointer
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-20 07:54:38 +01:00
Marco Costalba e8b7109eff Use enums instead of constants for piece values
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-20 00:08:34 +01:00
Marco Costalba 0c6ed5929c Document De Bruijn sequences
Insted of raw magic numbers.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-19 23:01:48 +01:00
Marco Costalba 2f4a9a140a Avoid wake up master thread when useless
Check we are the last slave of the split point
before to wake up the master. This should avoid
spurious wakes up.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-19 23:01:47 +01:00
Marco Costalba dba1bc354a Simplify idle_loop() signature
We can detect the split point master also from within idle_loop,
so we can call the function without parameters and remove an
overloaded member hack in Thread class.

Note that we don't need to take a lock around curSplitPoint
when entering idle_loop() because if we are the master then
curSplitPoint cannot change under our feet (because is_searching
is set and so we cannot be reallocated), if we are a slave
we enter idle_loop() only upon Thread creation and in that case
is always splitPointsCnt == 0. This is true even in the very rare
case that curSplitPoint != NULL, if we have been already allocated
even before entering idle_loop().

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-19 23:01:28 +01:00
Marco Costalba 4b19430103 Prefer size_t over int for array sizes
Align to standard library conventions.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-19 11:01:46 +01:00
Marco Costalba 7c1f8dbde9 Introduce namespace Bitbases
Let's continue this namespace galore...

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-18 13:08:12 +01:00
Marco Costalba 2c1ba2ab0d Introduce namespace UCI
Ater previous patch it comes naturally to take this
extra step.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-18 12:26:22 +01:00
Marco Costalba b011818917 Retire struct OptionsMap
Directly use the underlying std::map instead and avoid
a useless inheritance.

As a nice side-effect Options global object has now a
default c'tor avoiding possible issues with globals
initializations.

Suggested by Rein Halbersma.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-18 11:30:27 +01:00
Marco Costalba bc4de9edae Explicitly qualify STL functions
Suggested by Rein Halbersma.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-18 11:00:56 +01:00
Marco Costalba 9de4ee6d32 Retire MovePickerExt struct
Templetize MovePicker::next_move() member function instead. It
is easier and we also avoid the forwarding of MovePicker() c'tor
arguments in the common case.

Suggested by Rein Halbersma.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-08-18 10:46:24 +01:00
Marco Costalba 90ec4a403a Guard against 'divide by zero' in bench
Also remove an useless cast.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-07-30 18:05:15 +01:00
Joseph R. Prostko b61ec33f22 Added Haiku-specific changes to Makefile
First change: If Haiku is host platform, change
installation prefix to /boot/common/bin

Second change: Only link in pthreads if Haiku isn't
host platform.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-07-30 06:29:46 +01:00
Marco Costalba 1f7b5d9a79 Fix UCI promotion move notation
Regression introduced by revision
f0db6a6c0b

Spotted by Joona.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-07-26 18:16:24 +01:00
Linus Arver 5c6ba81cf2 Readme.txt: more grammar/style fixes 2012-07-19 12:09:39 -07:00
Linus Arver 591adf564a Readme.txt: grammar/stylistic fixes 2012-07-18 16:46:51 -07:00
Marco Costalba f0db6a6c0b Fix regression in move_to_san()
Broken since commit 628808a113

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-07-15 09:22:00 +01:00
Marco Costalba 520e680278 Introduce notation.h
And group there all the formatting functions but
uci_pv() that requires access to search.cpp variables.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-07-15 08:29:07 +01:00
Marco Costalba abc6a0be2f Rewrite pv_info_xxx() signatures
Use the helpers to format the PV info but without
writing to output stream (file or cout). Message
formatting and sending are two logically different
task.

Incidentaly reintroduce the pretty_pv() name,
from Glaurung memories :-)

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-07-15 07:48:33 +01:00
Marco Costalba 9dbda6652e Include castle moves in 'dangerous' flag
Simplifies the code and seems more natural.

We have a very small fucntional change becuase now
at PV nodes castles are extended one ply anyhow.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-07-14 12:29:11 +01:00
Marco Costalba 5dc0df8435 Merge exclusion search conditions
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-07-14 12:18:14 +01:00
Marco Costalba 6e5a334c95 Remove redundant condition in is_dangerous()
A pawn on 7th is always passed so retire
this redundant condition.

No funtional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-07-13 17:57:26 +01:00
Marco Costalba 6becc81446 Silence a MSVC warning in class Tie
With warning level 4 MSVC complains that a default
assignment operator could not be generated due to
member 'file' is a reference (warning C4512).

Use a pointer instead of a reference and move
struct Tie outisde class Logger while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-07-08 10:50:23 +01:00
Marco Costalba 6b5322ce00 Rename first_1 / last_1 in lsb / msb
It seems more accurate: lsb is clear while 'first
bit' depends from where you look at the bitboard.

And fix compile in case of 64 bits platforms that
do not use BSFQ intrinsics.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-07-08 09:36:40 +01:00
Marco Costalba 67d91dfd50 Use last_1() to compute new TT size
Transposition table consists of a power of 2
number of TTCluster entries.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-07-07 19:46:13 +01:00
Marco Costalba 089e54c7fd Revert to -O3 with Clang
Instead of -O4 option that does not work with both mingw and
Linux gcc (tested with Clang 3.1).

As reported by Reed Kotler:
Turns out that -O4 is not a valid option for clang unless you have
the proper gold linker and plugins built. That's because -O4 enables
LTO, which writes out bitcode files during the compile, and then loads
those and optimizes them during the link phase.

It requires a linker that supports LLVM's LTO. There is a plugin for
Gold available as part of LLVM.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-07-07 19:05:38 +01:00
Marco Costalba 0b3ffb54b7 Fix signedness warning in time_to_msec()
We have a signed integer here so let the return type
take in account that.

Found by Clang with -Weverything option.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-07-07 16:28:39 +01:00
Marco Costalba 775488340e More idiomatic signature for operator=()
Return a reference instead of void so to enable
chained assignments like

"p = q = Position(...);"

Suggested by Rein Halbersma.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-07-05 11:55:35 +01:00
Marco Costalba 7d2530873e Streamline null search reduction formula
Although a (little) functional change, we have no ELO change
but formula it is now more clear.

After 13019 games at 30"+0.05
Mod vs Orig 2075 - 2088 - 8856 ELO 0 (+- 3.4)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-07-05 11:48:17 +01:00