Community
cancel
Showing results for 
Search instead for 
Did you mean: 
max-divulskiy
Beginner
66 Views

POPCNT on multiple platforms

Jump to solution

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
Black Belt
66 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

1 Reply
TimP
Black Belt
67 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

Reply