1 /* { dg-do compile } */
2 /* { dg-options "-O2" } */
3
4 static const unsigned long long magic = 0x03f08c5392f756cdULL;
5
6 static const char table[64] = {
7 0, 1, 12, 2, 13, 22, 17, 3,
8 14, 33, 23, 36, 18, 58, 28, 4,
9 62, 15, 34, 26, 24, 48, 50, 37,
10 19, 55, 59, 52, 29, 44, 39, 5,
11 63, 11, 21, 16, 32, 35, 57, 27,
12 61, 25, 47, 49, 54, 51, 43, 38,
13 10, 20, 31, 56, 60, 46, 53, 42,
14 9, 30, 45, 41, 8, 40, 7, 6,
15 };
16
17 static inline int ctz1 (unsigned long long b)
18 {
19 unsigned long long lsb = b & -b;
20 return table[(lsb * magic) >> 58];
21 }
22
23 void f (unsigned long long x, int *p)
24 {
25 if (x != 0)
26 {
27 int a = ctz1 (x);
28 *p = a | p[a];
29 }
30 }
31
32 /* { dg-final { scan-assembler-times "rbit\t" 1 } } */
33 /* { dg-final { scan-assembler-times "clz\t" 1 } } */
34