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