Can't compile Stockfish with USE_POPCNT with Intel C++

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

gaard
Posts: 447
Joined: Mon Jun 07, 2010 3:13 am
Location: Holland, MI
Full name: Martin W

Can't compile Stockfish with USE_POPCNT with Intel C++

Post by gaard »

It links fine if I compile with MS' compiler, but if I use Intel's compiler, I get a linking error:

evaluate.obj : error LNK2019: unresolved external symbol __popcnt64 referenced in function "enum Value __cdecl __N_12_evaluate_cpp_06931d7d::do_evaluate<1>(class Position const &,enum Value &)" (??$do_evaluate@$00@__N_12_evaluate_cpp_06931d7d@@YA?AW4Value@@AEBVPosition@@AEAW41@@Z)
benchmark.exe : fatal error LNK1120: 1 unresolved externals
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Can't compile Stockfish with USE_POPCNT with Intel C++

Post by mcostalba »

gaard wrote:It links fine if I compile with MS' compiler, but if I use Intel's compiler, I get a linking error:

evaluate.obj : error LNK2019: unresolved external symbol __popcnt64 referenced in function "enum Value __cdecl __N_12_evaluate_cpp_06931d7d::do_evaluate<1>(class Position const &,enum Value &)" (??$do_evaluate@$00@__N_12_evaluate_cpp_06931d7d@@YA?AW4Value@@AEBVPosition@@AEAW41@@Z)
benchmark.exe : fatal error LNK1120: 1 unresolved externals
This is strange, anyhow please try the following patch:

Code: Select all

--- a/src/bitcount.h
+++ b/src/bitcount.h
@@ -85,9 +85,9 @@ template<>
 inline int count_1s<CNT_POPCNT>&#40;Bitboard b&#41; &#123;
 #if !defined&#40;USE_POPCNT&#41;
   return int&#40;b != 0&#41;; // Avoid 'b not used' warning
-#elif defined&#40;_MSC_VER&#41;
+#elif defined&#40;_MSC_VER&#41; && !defined&#40;__INTEL_COMPILER&#41;
   return __popcnt64&#40;b&#41;;
-#elif defined&#40;__GNUC__)
+#elif
   unsigned long ret;
   __asm__("popcnt %1, %0" &#58; "=r" &#40;ret&#41; &#58; "r" &#40;b&#41;);
   return ret;
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Can't compile Stockfish with USE_POPCNT with Intel C++

Post by mcostalba »

This should be a better patch:

Code: Select all

diff --git a/src/bitcount.h b/src/bitcount.h
index 0992c00..3c5ba2a 100644
--- a/src/bitcount.h
+++ b/src/bitcount.h
@@ -85,6 +85,8 @@ template<>
 inline int count_1s<CNT_POPCNT>&#40;Bitboard b&#41; &#123;
 #if !defined&#40;USE_POPCNT&#41;
   return int&#40;b != 0&#41;; // Avoid 'b not used' warning
+#elif defined&#40;_MSC_VER&#41; && defined&#40;__INTEL_COMPILER&#41;
+  return _mm_popcnt_u64&#40;b&#41;;
 #elif defined&#40;_MSC_VER&#41;
   return __popcnt64&#40;b&#41;;
 #elif defined&#40;__GNUC__)
diff --git a/src/types.h b/src/types.h
index 161117f..a379d54 100644
--- a/src/types.h
+++ b/src/types.h
@@ -86,6 +86,11 @@ typedef uint64_t Bitboard;
 #define USE_BSFQ
 #endif
 
+// Intel header for _mm_popcnt_u64&#40;) intrinsic
+#if defined&#40;USE_POPCNT&#41; && defined&#40;_MSC_VER&#41; && defined&#40;__INTEL_COMPILER&#41;
+#include <nmmintrin.h>
+#endif
+
 // Cache line alignment specification
 #if defined&#40;_MSC_VER&#41; || defined&#40;__INTEL_COMPILER&#41;
 #define CACHE_LINE_ALIGNMENT __declspec&#40;align&#40;64&#41;)
Unfortunatly we cannot test because we miss the hardware, so please report if it works for you and be so kind to report also the speed increase difference, if any.

Thanks
Marco
gaard
Posts: 447
Joined: Mon Jun 07, 2010 3:13 am
Location: Holland, MI
Full name: Martin W

Re: Can't compile Stockfish with USE_POPCNT with Intel C++

Post by gaard »

Compiles fine now.

bench 512 1 18

With POPCNT:

total time: 177.876
nodes: 165229644
Nodes/sec: 928903

Without POPCNT:

total time: 186.778
nodes: 165229644
Nodes/sec: 884631


Thanks a lot!
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Can't compile Stockfish with USE_POPCNT with Intel C++

Post by mcostalba »

gaard wrote:Compiles fine now.

bench 512 1 18

With POPCNT:

total time: 177.876
nodes: 165229644
Nodes/sec: 928903

Without POPCNT:

total time: 186.778
nodes: 165229644
Nodes/sec: 884631


Thanks a lot!
Sorry, what patch did you apply ? The first or the second one ?

Thanks
gaard
Posts: 447
Joined: Mon Jun 07, 2010 3:13 am
Location: Holland, MI
Full name: Martin W

Re: Can't compile Stockfish with USE_POPCNT with Intel C++

Post by gaard »

The last one. Still can't figure out why the MS linker was rejecting Intel's compile. I did a VERBOSE at the linking stage and all the same libraries were there.