# optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
# arch = (name) --- (-arch) --- Target architecture
# bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
-# prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch x86 asm-instruction
-# bsfq = yes/no --- -DUSE_BSFQ --- Use bsfq x86_64 asm-instruction (only
-# with GCC and ICC 64-bit)
-# popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt x86_64 asm-instruction
+# prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch asm-instruction
+# popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt asm-instruction
# sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
# pext = yes/no --- -DUSE_PEXT --- Use pext x86_64 asm-instruction
#
debug = no
bits = 32
prefetch = no
-bsfq = no
popcnt = no
sse = no
pext = no
arch = x86_64
bits = 64
prefetch = yes
- bsfq = yes
sse = yes
endif
arch = x86_64
bits = 64
prefetch = yes
- bsfq = yes
popcnt = yes
sse = yes
endif
arch = x86_64
bits = 64
prefetch = yes
- bsfq = yes
popcnt = yes
sse = yes
pext = yes
ifeq ($(ARCH),armv7)
arch = armv7
prefetch = yes
- bsfq = yes
endif
ifeq ($(ARCH),ppc-32)
CXXFLAGS += -DNO_PREFETCH
endif
-### 3.8 bsfq
-ifeq ($(bsfq),yes)
- CXXFLAGS += -DUSE_BSFQ
-endif
-
### 3.9 popcnt
ifeq ($(popcnt),yes)
ifeq ($(comp),icc)
@echo "arch: '$(arch)'"
@echo "bits: '$(bits)'"
@echo "prefetch: '$(prefetch)'"
- @echo "bsfq: '$(bsfq)'"
@echo "popcnt: '$(popcnt)'"
@echo "sse: '$(sse)'"
@echo "pext: '$(pext)'"
test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
@test "$(bits)" = "32" || test "$(bits)" = "64"
@test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
- @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
@test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
@test "$(sse)" = "yes" || test "$(sse)" = "no"
@test "$(pext)" = "yes" || test "$(pext)" = "no"
}
}
-#ifndef USE_BSFQ
+#ifdef NO_BSF
/// Software fall-back of lsb() and msb() for CPU lacking hardware support
return Square(result + MSBTable[b32]);
}
-#endif // ifndef USE_BSFQ
+#endif // ifdef NO_BSF
/// Bitboards::pretty() returns an ASCII representation of a bitboard suitable
/// lsb() and msb() return the least/most significant bit in a non-zero bitboard
-#ifdef USE_BSFQ
+#if defined(__GNUC__)
-# if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
+inline Square lsb(Bitboard b) { return Square(__builtin_ctzll(b)); }
+inline Square msb(Bitboard b) { return Square(63 - __builtin_clzll(b)); }
+
+#elif defined(_WIN64) && defined(_MSC_VER)
inline Square lsb(Bitboard b) {
unsigned long idx;
return (Square) idx;
}
-# elif defined(__arm__)
-
-inline int lsb32(uint32_t v) {
- __asm__("rbit %0, %1" : "=r"(v) : "r"(v));
- return __builtin_clz(v);
-}
-
-inline Square msb(Bitboard b) {
- return (Square) (63 - __builtin_clzll(b));
-}
-
-inline Square lsb(Bitboard b) {
- return (Square) (uint32_t(b) ? lsb32(uint32_t(b)) : 32 + lsb32(uint32_t(b >> 32)));
-}
-
-# else // Assumed gcc or compatible compiler
-
-inline Square lsb(Bitboard b) { // Assembly code by Heinz van Saanen
- Bitboard idx;
- __asm__("bsfq %1, %0": "=r"(idx): "rm"(b) );
- return (Square) idx;
-}
-
-inline Square msb(Bitboard b) {
- Bitboard idx;
- __asm__("bsrq %1, %0": "=r"(idx): "rm"(b) );
- return (Square) idx;
-}
-
-# endif
+#else
-#else // ifdef(USE_BSFQ)
+#define NO_BSF // Fallback on software implementation for other cases
Square lsb(Bitboard b);
Square msb(Bitboard b);
#if defined(_WIN64) && defined(_MSC_VER) // No Makefile used
# include <intrin.h> // MSVC popcnt and bsfq instrinsics
# define IS_64BIT
-# define USE_BSFQ
#endif
#if defined(USE_POPCNT) && defined(__INTEL_COMPILER) && defined(_MSC_VER)