1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-11 19:49:14 +00:00

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>
This commit is contained in:
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

@ -52,9 +52,9 @@ UCI parameter "Book File".
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

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;
} }
ret = Square(BitTable[((~(u.dw.h ^ (u.dw.h - 1))) * 0x783a9b23) >> 26]);
*((uint32_t*)bb+1) = u.dw.h & (u.dw.h - 1); // Little endian only? u.dw.h &= (u.dw.h - 1);
return Square(BitTable[((~(u.dw.h ^ (u.dw.h - 1))) * 0x783a9b23) >> 26]); *bb = u.b;
return ret;
} }
#endif #endif