| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-O2" } */ |
| 3 |
|
| 4 |
typedef unsigned long gr; |
| 5 |
|
| 6 |
template <int l, int r> |
| 7 |
struct mask { |
| 8 |
enum { value = (1ul << r) - (1ul << l) }; |
| 9 |
}; |
| 10 |
|
| 11 |
template <int l> |
| 12 |
struct mask<l, sizeof (gr) * __CHAR_BIT__> { |
| 13 |
enum { value = -(1ul << l) }; |
| 14 |
}; |
| 15 |
|
| 16 |
__attribute__ ((noipa)) void |
| 17 |
test (gr a, gr b, gr mask, gr out) |
| 18 |
{ |
| 19 |
if (((a & mask) | (b & ~mask)) != out) |
| 20 |
__builtin_abort (); |
| 21 |
} |
| 22 |
|
| 23 |
__attribute__ ((noipa)) gr |
| 24 |
no_optimize (gr x) |
| 25 |
{ |
| 26 |
return x; |
| 27 |
} |
| 28 |
|
| 29 |
template <int l, int r> |
| 30 |
struct test1 { |
| 31 |
static void |
| 32 |
run (void) |
| 33 |
{ |
| 34 |
gr m = mask<l, r>::value; |
| 35 |
gr a = no_optimize (-1ul); |
| 36 |
gr b = no_optimize (0); |
| 37 |
|
| 38 |
test (a, b, m, (a & m) | (b & ~m)); |
| 39 |
test (a, b, ~m, (a & ~m) | (b & m)); |
| 40 |
test (a, 0, ~m, a & ~m); |
| 41 |
|
| 42 |
test1<l, r + 1>::run (); |
| 43 |
} |
| 44 |
}; |
| 45 |
|
| 46 |
template <int l> |
| 47 |
struct test1<l, sizeof (gr) * __CHAR_BIT__ + 1> { |
| 48 |
static void run (void) {} |
| 49 |
}; |
| 50 |
|
| 51 |
template <int l> |
| 52 |
void |
| 53 |
test2 (void) |
| 54 |
{ |
| 55 |
test1<l, l + 1>::run (); |
| 56 |
test2<l + 1> (); |
| 57 |
} |
| 58 |
|
| 59 |
template <> void test2<sizeof (gr) * __CHAR_BIT__> (void) {} |
| 60 |
|
| 61 |
int |
| 62 |
main () |
| 63 |
{ |
| 64 |
test2<0> (); |
| 65 |
} |