blob: 9f10ccc3b5107d8dc39ac1da20db178c692e2146 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
/* PR tree-optimization/114760 */
/* { dg-do compile } */
/* { dg-require-effective-target clz } */
/* { dg-require-effective-target ctz } */
/* { dg-options "-O3 -fdump-tree-optimized" } */
unsigned
ntz32_1 (unsigned x)
{
int n = 32;
while (x != 0)
{
n = n - 1;
x = x * 2;
}
return n;
}
unsigned
ntz32_2 (unsigned x)
{
int n = 32;
while (x != 0)
{
n = n - 1;
x = x + x;
}
return n;
}
unsigned
ntz32_3 (unsigned x)
{
int n = 32;
while (x != 0)
{
n = n - 1;
x = x << 1;
}
return n;
}
#define PREC (__CHAR_BIT__ * __SIZEOF_INT__)
int
nlz32_1 (unsigned int b) {
int c = PREC;
while (b != 0) {
b >>= 1;
c --;
}
return c;
}
int
nlz32_2 (unsigned int b) {
int c = PREC;
while (b != 0) {
b /= 2;
c --;
}
return c;
}
/* { dg-final { scan-tree-dump-times "__builtin_ctz|\\.CTZ" 3 "optimized" } } */
/* { dg-final { scan-tree-dump-times "__builtin_clz|\\.CLZ" 2 "optimized" } } */
|