-#elif defined(BITCOUNT_SWAR_64)
-
-inline int sw_count_1s(Bitboard b) {
- b -= ((b>>1) & 0x5555555555555555ULL);
- b = ((b>>2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
- b = ((b>>4) + b) & 0x0F0F0F0F0F0F0F0FULL;
- b *= 0x0101010101010101ULL;
- return int(b >> 56);
-}
-
-inline int sw_count_1s_max_15(Bitboard b) {
- b -= (b>>1) & 0x5555555555555555ULL;
- b = ((b>>2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
- b *= 0x1111111111111111ULL;
- return int(b >> 60);
-}
-
-#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) : sw_count_1s(b);
-}
-
-template<bool UseIntrinsic>
-inline int count_1s_max_15(Bitboard b) {
-
- return UseIntrinsic ? POPCNT_INTRINSIC(b) : sw_count_1s_max_15(b);
+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;
+#endif