-#endif // BITCOUNT
-
-
-/// count_1s() counts the number of nonzero bits in a bitboard.
-/// If template parameter is true an intrinsic is called, otherwise
-/// we fallback on a software implementation.
-
-template<bool UseIntrinsic>
-inline int count_1s(Bitboard b) {
-
- return UseIntrinsic ? POPCNT_INTRINSIC(b) : count_1s(b);
-}
-
-template<bool UseIntrinsic>
-inline int count_1s_max_15(Bitboard b) {
-
- return UseIntrinsic ? POPCNT_INTRINSIC(b) : count_1s_max_15(b);
-}
-
-
-// Detect hardware POPCNT support
-inline bool cpu_has_popcnt() {
-
- int CPUInfo[4] = {-1};
- __cpuid(CPUInfo, 0x00000001);
- return (CPUInfo[2] >> 23) & 1;
-}
-
-
-// Global constant initialized at startup that is set to true if
-// CPU on which application runs supports POPCNT intrinsic. Unless
-// USE_POPCNT is not defined.
-#if defined(USE_POPCNT)
-const bool CpuHasPOPCNT = cpu_has_popcnt();
-#else
-const bool CpuHasPOPCNT = false;
-#endif
-
-
-// Global constant used to print info about the use of 64 optimized
-// functions to verify that a 64 bit compile has been correctly built.
-#if defined(IS_64BIT)
-const bool CpuHas64BitPath = true;
-#else
-const bool CpuHas64BitPath = false;
+template<>
+inline int count_1s<CNT_POPCNT>(Bitboard b) {
+#if !defined(USE_POPCNT)
+ return int(b != 0); // Avoid 'b not used' warning
+#elif defined(_MSC_VER) && defined(__INTEL_COMPILER)
+ return _mm_popcnt_u64(b);
+#elif defined(_MSC_VER)
+ return (int)__popcnt64(b);
+#elif defined(__GNUC__)
+ unsigned long ret;
+ __asm__("popcnt %1, %0" : "=r" (ret) : "r" (b));
+ return ret;