Pradu wrote:bob wrote:Actually I believe it is supported on any processor that has the sse 4.2 flag set when you use the CPUID instruction.
There's even a seperate flag just for popcnt so that it can work with CPUs that have popcnt but not SSE4:
Code: Select all
#ifdef _MSC_VER
#include <intrin.h>
#elif defined( __GNUC__ )
static __inline__ __attribute__((always_inline)) void __cpuid(int CPUInfo[], const int InfoType)
{
__asm__ __volatile__
(
"cpuid"
: "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3])
: "a" (InfoType)
);
}
#else
#error Unsupported Compiler
#endif
...
int CPUInfo[4];
__cpuid(CPUInfo, 1);
int has_popcnt = (CPUInfo[2]>>23)&1;
I have one question regarding runtime check of CPU capabilities.
How this can be used for a chess engine that is supposed to be released as a binary and downloaded and used by anyone on any computer ?
I mean, I cannot use a function pointer to redirect at runtime on a fallback standard C code implementation if host CPU does not support POPCNT. That would be far too slow. This kind of functions must be inlined. So, when I check that host CPU has or not has the popcnt capability what can I do ?
Chess engine is not supposed to be compiled on _any_ pc that will run it, but is compiled once with the best optimization and distributed.
The only possibility I foreseen is two create two compiles, one for CPU with POPCNT and another for CPU without POPCNT, but considering that we need also another two versions for 32 and 64 bits we are ramping up fast on this combinatorial escalation.