Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

POPCNT on multiple platforms

max-divulskiy
Beginner
491 Views

Good afternoon.

I have some function for calculate parity number on any x86 computers:

Source: http://graphics.stanford.edu/~seander/bithacks.html#ParityNaive

[bash]static const bool ParityTable256[256] =
{
#   define P2(n) n, n^1, n^1, n
#   define P4(n) P2(n), P2(n^1), P2(n^1), P2(n)
#   define P6(n) P4(n), P4(n^1), P4(n^1), P4(n)
      P6(0), P6(1), P6(1), P6(0)
};

unsigned int __forceinline parity(unsigned __int32 v)
{
      v ^= v >> 16;
      v ^= v >> 8;
      return ParityTable256[v & 0xff];
}
[/bash]

and for computer with SSE4.2 instruction:

[bash]UINT __forceinline parity( UINT32 word )
{
	return _mm_popcnt_u32( word ) & 1;
}[/bash]

How force compiler create two code branches for x86 proccessor and proccesor with SSE 4.2, but without using of CPUID instruction?
0 Kudos
1 Solution
TimP
Honored Contributor III
491 Views
It's a little strange that the original documentation comes up first in a search, and so you want the current names for use in icc.
I would advise testing this on every platform each time you change library versions.

View solution in original post

0 Kudos
1 Reply
TimP
Honored Contributor III
492 Views
It's a little strange that the original documentation comes up first in a search, and so you want the current names for use in icc.
I would advise testing this on every platform each time you change library versions.
0 Kudos
Reply