1
0
Fork 0

Big-endian compatible pop_1st_bit()

Thanks to Eric Mullins we have now endian friendly
pop_1st_bit() and also is removed the need to use
-fno-strict-aliasing compiler option with GCC.

Speed is almost as fast, very small difference if any in
perft test, so I assume almost no difference in real games.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
sf_2.3.1_base
Marco Costalba 2009-11-05 19:29:26 +01:00
parent a9e536a7eb
commit dc286d2673
3 changed files with 120 additions and 104 deletions

View File

@ -1,91 +1,91 @@
1. Introduction 1. Introduction
--------------- ---------------
Stockfish is a free UCI chess engine derived from Glaurung 2.1. It is Stockfish is a free UCI chess engine derived from Glaurung 2.1. It is
not a complete chess program, but requires some UCI compatible GUI not a complete chess program, but requires some UCI compatible GUI
(like XBoard with PolyGlot, eboard, Jos<6F>, Arena, Sigma Chess, Shredder, (like XBoard with PolyGlot, eboard, Jos<6F>, Arena, Sigma Chess, Shredder,
Chess Partner, or Fritz) in order to be used comfortably. Read the Chess Partner, or Fritz) in order to be used comfortably. Read the
documentation for your GUI of choice for information about how to use documentation for your GUI of choice for information about how to use
Stockfish with your GUI. Stockfish with your GUI.
This version of Stockfish supports up to 8 CPUs, but has not been This version of Stockfish supports up to 8 CPUs, but has not been
tested thoroughly with more than 2. The program tries to detect the tested thoroughly with more than 2. The program tries to detect the
number of CPUs on your computer and set the number of search threads number of CPUs on your computer and set the number of search threads
accordingly, but please be aware that the detection is not always accordingly, but please be aware that the detection is not always
correct. It is therefore recommended to inspect the value of the correct. It is therefore recommended to inspect the value of the
"Threads" UCI parameter, and to make sure it equals the number of CPU "Threads" UCI parameter, and to make sure it equals the number of CPU
cores on your computer. If you are using more than four threads, it cores on your computer. If you are using more than four threads, it
is recommended to raise the value of "Minimum Split Depth" UCI parameter is recommended to raise the value of "Minimum Split Depth" UCI parameter
to 6. to 6.
2. Files 2. Files
-------- --------
This distribution of Stockfish consists of the following files: This distribution of Stockfish consists of the following files:
* Readme.txt, the file you are currently reading. * Readme.txt, the file you are currently reading.
* Copying.txt, a text file containing the GNU General Public * Copying.txt, a text file containing the GNU General Public
License. License.
* src/, a subdirectory containing the full source code, including a * src/, a subdirectory containing the full source code, including a
Makefile that can be used to compile Stockfish on Unix-like Makefile that can be used to compile Stockfish on Unix-like
systems. For further information about how to compile Stockfish systems. For further information about how to compile Stockfish
yourself, read section 4 below. yourself, read section 4 below.
* polyglot.ini, for using Stockfish with Fabien Letouzey's PolyGlot * polyglot.ini, for using Stockfish with Fabien Letouzey's PolyGlot
adapter. adapter.
3. Opening books 3. Opening books
---------------- ----------------
This version of Stockfish has experimental support for PolyGlot opening This version of Stockfish has experimental support for PolyGlot opening
books. For information about how to create such books, consult the books. For information about how to create such books, consult the
PolyGlot documentation. The book file can be selected by setting the PolyGlot documentation. The book file can be selected by setting the
UCI parameter "Book File". UCI parameter "Book File".
4. Compiling it yourself 4. Compiling it yourself
------------------------ ------------------------
On Unix-like systems, it should usually be possible to compile On Unix-like systems, it should usually be possible to compile
Stockfish directly from the source code with the included Makefile. Stockfish directly from the source code with the included Makefile.
The exception is computer with big-endian CPUs, like PowerPC
Macintoshes. Some of the bitboard routines in the current version of For big-endian machines like Power PC you need to enable the proper
Stockfish are endianness-sensitive, and won't work on a big-endian CPU. flag changing from -DNBIGENDIAN to -DBIGENDIAN in the Makefile.
Stockfish has POPCNT instruction runtime detection and support. This can Stockfish has POPCNT instruction runtime detection and support. This can
give an extra speed on Core i7 or similar systems. To enable this feature give an extra speed on Core i7 or similar systems. To enable this feature
(disabled by default) simply uncomment #define USE_POPCNT in bitcount.h (disabled by default) simply uncomment #define USE_POPCNT in bitcount.h
before to compile. before to compile.
On 64 bit Unix-like systems the 'bsfq' assembly instruction will be used On 64 bit Unix-like systems the 'bsfq' assembly instruction will be used
for bit counting. Detection is automatic at compile time, but in case you for bit counting. Detection is automatic at compile time, but in case you
experience compile problems you can comment out #define USE_BSFQ line in types.h experience compile problems you can comment out #define USE_BSFQ line in types.h
5. Terms of use 5. Terms of use
--------------- ---------------
Stockfish is free, and distributed under the GNU General Public License Stockfish is free, and distributed under the GNU General Public License
(GPL). Essentially, this means that you are free to do almost exactly (GPL). Essentially, this means that you are free to do almost exactly
what you want with the program, including distributing it among your what you want with the program, including distributing it among your
friends, making it available for download from your web site, selling friends, making it available for download from your web site, selling
it (either by itself or as part of some bigger software package), or it (either by itself or as part of some bigger software package), or
using it as the starting point for a software project of your own. using it as the starting point for a software project of your own.
The only real limitation is that whenever you distribute Stockfish in The only real limitation is that whenever you distribute Stockfish in
some way, you must always include the full source code, or a pointer some way, you must always include the full source code, or a pointer
to where the source code can be found. If you make any changes to the to where the source code can be found. If you make any changes to the
source code, these changes must also be made available under the GPL. source code, these changes must also be made available under the GPL.
For full details, read the copy of the GPL found in the file named For full details, read the copy of the GPL found in the file named
Copying.txt. Copying.txt.
6. Feedback 6. Feedback
----------- -----------
The author's e-mail address is mcostalba@gmail.com The author's e-mail address is mcostalba@gmail.com

View File

@ -39,6 +39,14 @@ ICCFLAGS += -DNDEBUG
ICCFLAGS-OSX += -DNDEBUG ICCFLAGS-OSX += -DNDEBUG
### ==========================================================================
### Enable/disable compile for a big-endian CPU, disabled by default
### ==========================================================================
GCCFLAGS += -DNBIGENDIAN
ICCFLAGS += -DNBIGENDIAN
ICCFLAGS-OSX += -DNBIGENDIAN
### ========================================================================== ### ==========================================================================
### Run built-in benchmark for pgo-builds with: 32MB hash 1 thread 10 depth ### Run built-in benchmark for pgo-builds with: 32MB hash 1 thread 10 depth
### These settings are generally fast, but may be changed experimentally ### These settings are generally fast, but may be changed experimentally
@ -47,9 +55,9 @@ PGOBENCH = ./$(EXE) bench 32 1 10 default depth
### General compiler settings. Do not change ### General compiler settings. Do not change
GCCFLAGS += -g -Wall -fno-exceptions -fno-rtti -fno-strict-aliasing GCCFLAGS += -g -Wall -fno-exceptions -fno-rtti
ICCFLAGS += -g -Wall -fno-exceptions -fno-rtti -fno-strict-aliasing -wd383,869,981,10187,10188,11505,11503 ICCFLAGS += -g -Wall -fno-exceptions -fno-rtti -wd383,869,981,10187,10188,11505,11503
ICCFLAGS-OSX += -g -Wall -fno-exceptions -fno-rtti -fno-strict-aliasing -wd383,869,981,10187,10188,11505,11503 ICCFLAGS-OSX += -g -Wall -fno-exceptions -fno-rtti -wd383,869,981,10187,10188,11505,11503
### General linker settings. Do not change ### General linker settings. Do not change

View File

@ -317,8 +317,8 @@ Square pop_1st_bit(Bitboard* b) {
#elif !defined(USE_BSFQ) #elif !defined(USE_BSFQ)
CACHE_LINE_ALIGNMENT static CACHE_LINE_ALIGNMENT
static const int BitTable[64] = { const int BitTable[64] = {
63, 30, 3, 32, 25, 41, 22, 33, 15, 50, 42, 13, 11, 53, 19, 34, 61, 29, 2, 63, 30, 3, 32, 25, 41, 22, 33, 15, 50, 42, 13, 11, 53, 19, 34, 61, 29, 2,
51, 21, 43, 45, 10, 18, 47, 1, 54, 9, 57, 0, 35, 62, 31, 40, 4, 49, 5, 52, 51, 21, 43, 45, 10, 18, 47, 1, 54, 9, 57, 0, 35, 62, 31, 40, 4, 49, 5, 52,
26, 60, 6, 23, 44, 46, 27, 56, 16, 7, 39, 48, 24, 59, 14, 12, 55, 38, 28, 26, 60, 6, 23, 44, 46, 27, 56, 16, 7, 39, 48, 24, 59, 14, 12, 55, 38, 28,
@ -336,26 +336,34 @@ union b_union {
Bitboard b; Bitboard b;
struct { struct {
#if defined (BIGENDIAN)
uint32_t h;
uint32_t l;
#else
uint32_t l; uint32_t l;
uint32_t h; uint32_t h;
#endif
} dw; } dw;
}; };
// WARNING: Needs -fno-strict-aliasing compiler option
Square pop_1st_bit(Bitboard* bb) { Square pop_1st_bit(Bitboard* bb) {
b_union u; b_union u;
Square ret;
u.b = *bb; u.b = *bb;
if (u.dw.l) if (u.dw.l)
{ {
*((uint32_t*)bb) = u.dw.l & (u.dw.l - 1); ret = Square(BitTable[((u.dw.l ^ (u.dw.l - 1)) * 0x783a9b23) >> 26]);
return Square(BitTable[((u.dw.l ^ (u.dw.l - 1)) * 0x783a9b23) >> 26]); u.dw.l &= (u.dw.l - 1);
} *bb = u.b;
return ret;
*((uint32_t*)bb+1) = u.dw.h & (u.dw.h - 1); // Little endian only? }
return Square(BitTable[((~(u.dw.h ^ (u.dw.h - 1))) * 0x783a9b23) >> 26]); ret = Square(BitTable[((~(u.dw.h ^ (u.dw.h - 1))) * 0x783a9b23) >> 26]);
u.dw.h &= (u.dw.h - 1);
*bb = u.b;
return ret;
} }
#endif #endif