| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-fdump-tree-crc-details -O2" } */ |
| 3 |
|
| 4 |
// File - reliable_text.c |
| 5 |
#include <stdint.h> |
| 6 |
char calculateCRC8_(char* input, int length) |
| 7 |
{ |
| 8 |
unsigned char generator = 0x1D; |
| 9 |
unsigned char crc = 0x00; |
| 10 |
|
| 11 |
while (length > 0) |
| 12 |
{ |
| 13 |
unsigned char ch = *input++; |
| 14 |
length--; |
| 15 |
|
| 16 |
|
| 17 |
if (ch == 0) break; |
| 18 |
|
| 19 |
crc ^= ch; |
| 20 |
|
| 21 |
for (int i = 0; i < 8; i++) |
| 22 |
{ |
| 23 |
if ((crc & 0x80) != 0) |
| 24 |
{ |
| 25 |
crc = (unsigned char)((crc << 1) ^ generator); |
| 26 |
} |
| 27 |
else |
| 28 |
{ |
| 29 |
crc <<= 1; |
| 30 |
} |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
return crc; |
| 35 |
} |
| 36 |
|
| 37 |
/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ |