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