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
parent
a9e536a7eb
commit
dc286d2673
|
@ -52,9 +52,9 @@ UCI parameter "Book File".
|
|||
|
||||
On Unix-like systems, it should usually be possible to compile
|
||||
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
|
||||
Stockfish are endianness-sensitive, and won't work on a big-endian CPU.
|
||||
|
||||
For big-endian machines like Power PC you need to enable the proper
|
||||
flag changing from -DNBIGENDIAN to -DBIGENDIAN in the Makefile.
|
||||
|
||||
Stockfish has POPCNT instruction runtime detection and support. This can
|
||||
give an extra speed on Core i7 or similar systems. To enable this feature
|
||||
|
|
14
src/Makefile
14
src/Makefile
|
@ -39,6 +39,14 @@ ICCFLAGS += -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
|
||||
### 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
|
||||
GCCFLAGS += -g -Wall -fno-exceptions -fno-rtti -fno-strict-aliasing
|
||||
ICCFLAGS += -g -Wall -fno-exceptions -fno-rtti -fno-strict-aliasing -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
|
||||
GCCFLAGS += -g -Wall -fno-exceptions -fno-rtti
|
||||
ICCFLAGS += -g -Wall -fno-exceptions -fno-rtti -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
|
||||
|
|
|
@ -317,8 +317,8 @@ Square pop_1st_bit(Bitboard* b) {
|
|||
|
||||
#elif !defined(USE_BSFQ)
|
||||
|
||||
CACHE_LINE_ALIGNMENT
|
||||
static const int BitTable[64] = {
|
||||
static CACHE_LINE_ALIGNMENT
|
||||
const int BitTable[64] = {
|
||||
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,
|
||||
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;
|
||||
struct {
|
||||
#if defined (BIGENDIAN)
|
||||
uint32_t h;
|
||||
uint32_t l;
|
||||
#else
|
||||
uint32_t l;
|
||||
uint32_t h;
|
||||
#endif
|
||||
} dw;
|
||||
};
|
||||
|
||||
// WARNING: Needs -fno-strict-aliasing compiler option
|
||||
Square pop_1st_bit(Bitboard* bb) {
|
||||
|
||||
b_union u;
|
||||
b_union u;
|
||||
Square ret;
|
||||
|
||||
u.b = *bb;
|
||||
u.b = *bb;
|
||||
|
||||
if (u.dw.l)
|
||||
{
|
||||
*((uint32_t*)bb) = u.dw.l & (u.dw.l - 1);
|
||||
return Square(BitTable[((u.dw.l ^ (u.dw.l - 1)) * 0x783a9b23) >> 26]);
|
||||
}
|
||||
|
||||
*((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]);
|
||||
if (u.dw.l)
|
||||
{
|
||||
ret = Square(BitTable[((u.dw.l ^ (u.dw.l - 1)) * 0x783a9b23) >> 26]);
|
||||
u.dw.l &= (u.dw.l - 1);
|
||||
*bb = u.b;
|
||||
return ret;
|
||||
}
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue