| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-fdump-tree-crc-details -O2" } */ |
| 3 |
|
| 4 |
// crc32.i |
| 5 |
// We don't support this case. |
| 6 |
|
| 7 |
#include <stddef.h> |
| 8 |
typedef unsigned int u32; |
| 9 |
u32 gf2_multiply(u32 x, u32 y, u32 modulus) |
| 10 |
{ |
| 11 |
u32 product = x & 1 ? y : 0; |
| 12 |
int i; |
| 13 |
|
| 14 |
for (i = 0; i < 31; i++) { |
| 15 |
product = (product >> 1) ^ (product & 1 ? modulus : 0); |
| 16 |
x >>= 1; |
| 17 |
product ^= x & 1 ? y : 0; |
| 18 |
} |
| 19 |
|
| 20 |
return product; |
| 21 |
} |
| 22 |
|
| 23 |
u32 crc32_generic_shift(u32 crc, size_t len, |
| 24 |
u32 polynomial) |
| 25 |
{ |
| 26 |
u32 power = 0x2101; |
| 27 |
int i; |
| 28 |
|
| 29 |
for (i = 0; i < 8 * (int)(len & 3); i++) |
| 30 |
crc = (crc >> 1) ^ (crc & 1 ? 0x2101 : 0); |
| 31 |
|
| 32 |
len >>= 2; |
| 33 |
if (!len) |
| 34 |
return crc; |
| 35 |
|
| 36 |
for (;;) { |
| 37 |
|
| 38 |
if (len & 1) |
| 39 |
crc = gf2_multiply(crc, power, polynomial); |
| 40 |
|
| 41 |
len >>= 1; |
| 42 |
if (!len) |
| 43 |
break; |
| 44 |
|
| 45 |
|
| 46 |
power = gf2_multiply(power, power, polynomial); |
| 47 |
} |
| 48 |
|
| 49 |
return crc; |
| 50 |
} |
| 51 |
|
| 52 |
/* { dg-final { scan-tree-dump "Loop iteration number isn't a constant." "crc" } } */ |
| 53 |
/* { dg-final { scan-tree-dump "Loop iteration number is 30" "crc" } } */ |