1 /* { dg-do compile } */
2 /* { dg-require-effective-target popcountl } */
3 /* { dg-options "-O2 -fdump-tree-optimized" } */
4
5 #if __SIZEOF_LONG__ == 4
6 const unsigned long m1 = 0x55555555UL;
7 const unsigned long m2 = 0x33333333UL;
8 const unsigned long m4 = 0x0F0F0F0FUL;
9 const unsigned long h01 = 0x01010101UL;
10 const int shift = 24;
11 #else
12 const unsigned long m1 = 0x5555555555555555UL;
13 const unsigned long m2 = 0x3333333333333333UL;
14 const unsigned long m4 = 0x0f0f0f0f0f0f0f0fUL;
15 const unsigned long h01 = 0x0101010101010101UL;
16 const int shift = 56;
17 #endif
18
19
popcount64c(unsigned long x)20 int popcount64c(unsigned long x)
21 {
22 x -= (x >> 1) & m1;
23 x = (x & m2) + ((x >> 2) & m2);
24 x = (x + (x >> 4)) & m4;
25 return (x * h01) >> shift;
26 }
27
28 /* { dg-final { scan-tree-dump-times "\.POPCOUNT" 1 "optimized" } } */
29
30
31