| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-fdump-tree-crc-details" } */ |
| 3 |
/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-g" "-Os" "-funroll-loops" "-fpeel-loops" "-flto" } } */ |
| 4 |
|
| 5 |
#include <stddef.h> |
| 6 |
|
| 7 |
typedef unsigned char uint8_t; |
| 8 |
|
| 9 |
uint8_t gencrc (uint8_t *message, size_t len) { |
| 10 |
uint8_t crc = 0; |
| 11 |
size_t i, j; |
| 12 |
for (i = 0; i < len; i++) { |
| 13 |
uint8_t data = message[i]; |
| 14 |
for (j = 0; j < 8; j++) { |
| 15 |
if (((crc & 0x80) ^ (data & 0x80)) != 0) |
| 16 |
crc = (uint8_t) ((crc << 1) ^ 0x31); |
| 17 |
else |
| 18 |
crc <<= 1; |
| 19 |
data <<=1; |
| 20 |
} |
| 21 |
} |
| 22 |
return crc; |
| 23 |
} |
| 24 |
|
| 25 |
int main() |
| 26 |
{ |
| 27 |
uint8_t message[] = "Hello world!"; |
| 28 |
if (gencrc(message, 12) != 0x24) |
| 29 |
__builtin_abort (); |
| 30 |
__builtin_exit (0); |
| 31 |
} |
| 32 |
|
| 33 |
/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ |
| 34 |
/* { dg-final { scan-tree-dump-times "Couldn't generate faster CRC code." 0 "crc" } } */ |