| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-fdump-tree-crc-details -w" } */ |
| 3 |
/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ |
| 4 |
/* { dg-require-effective-target int32plus } */ |
| 5 |
|
| 6 |
#include <stdlib.h> |
| 7 |
|
| 8 |
typedef unsigned short ee_u16; |
| 9 |
typedef unsigned char ee_u8; |
| 10 |
|
| 11 |
__attribute__ ((noinline,optimize(0))) |
| 12 |
ee_u16 crcu8_O0 (ee_u8 data, ee_u16 crc) { |
| 13 |
ee_u8 i = 0, x16 = 0, carry = 0; |
| 14 |
for (i = 0; i < 8; i++) { |
| 15 |
x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); |
| 16 |
data >>= 1; |
| 17 |
if (x16 == 1) { |
| 18 |
crc ^= 0x4002; |
| 19 |
carry = 1; |
| 20 |
} else |
| 21 |
carry = 0; |
| 22 |
crc >>= 1; |
| 23 |
if (carry) |
| 24 |
crc |= 0x8000; |
| 25 |
else |
| 26 |
crc &= 0x7fff; |
| 27 |
} |
| 28 |
return crc; |
| 29 |
} |
| 30 |
|
| 31 |
ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { |
| 32 |
ee_u8 i = 0, x16 = 0, carry = 0; |
| 33 |
for (i = 0; i < 8; i++) { |
| 34 |
x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); |
| 35 |
data >>= 1; |
| 36 |
if (x16 == 1) { |
| 37 |
crc ^= 0x4002; |
| 38 |
carry = 1; |
| 39 |
} else |
| 40 |
carry = 0; |
| 41 |
crc >>= 1; |
| 42 |
if (carry) |
| 43 |
crc |= 0x8000; |
| 44 |
else |
| 45 |
crc &= 0x7fff; |
| 46 |
} |
| 47 |
return crc; |
| 48 |
} |
| 49 |
|
| 50 |
int main () |
| 51 |
{ |
| 52 |
ee_u16 crc = 0x0D80; |
| 53 |
for (ee_u8 i = 0; i < 255; i++) |
| 54 |
{ |
| 55 |
ee_u16 res1 = crcu8_O0 (i, crc); |
| 56 |
ee_u16 res2 = crcu8 (i, crc); |
| 57 |
if (res1 != res2) |
| 58 |
__builtin_abort (); |
| 59 |
crc = res1; |
| 60 |
} |
| 61 |
__builtin_exit (0); |
| 62 |
} |
| 63 |
/* { dg-final { scan-tree-dump "crcu8 function maybe contains CRC calculation." "crc" } } */ |
| 64 |
/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc" } } */ |
| 65 |
/* { dg-final { scan-tree-dump "Bit reversed" "crc" } } */ |
| 66 |
/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ |
| 67 |
/* { dg-final { scan-tree-dump "Polynomial's value is \\\{\[0, \]*1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1\\\}" "crc" } } */ |
| 68 |
/* { dg-final { scan-tree-dump-times "Couldn't generate faster CRC code." 0 "crc"} } */ |