| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-fdump-tree-crc-details" } */ |
| 3 |
/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto"} } */ |
| 4 |
/* { dg-require-effective-target int32plus } */ |
| 5 |
|
| 6 |
#include <stdint.h> |
| 7 |
#include <stdlib.h> |
| 8 |
|
| 9 |
__attribute__ ((noinline,optimize(0))) |
| 10 |
uint16_t crc_xmodem_update_O0 (uint16_t crc, uint8_t data) { |
| 11 |
int i; |
| 12 |
crc = crc ^ ((uint16_t) data << 8); |
| 13 |
for (i = 0; i < 8; i++) { |
| 14 |
if (crc & 0x8000) |
| 15 |
crc = (crc << 1) ^ 0x1021; |
| 16 |
else |
| 17 |
crc <<= 1; |
| 18 |
} |
| 19 |
return crc; |
| 20 |
} |
| 21 |
|
| 22 |
uint16_t crc_xmodem_update (uint16_t crc, uint8_t data) { |
| 23 |
int i; |
| 24 |
crc = crc ^ ((uint16_t) data << 8); |
| 25 |
for (i = 0; i < 8; i++) { |
| 26 |
if (crc & 0x8000) |
| 27 |
crc = (crc << 1) ^ 0x1021; |
| 28 |
else |
| 29 |
crc <<= 1; |
| 30 |
} |
| 31 |
return crc; |
| 32 |
} |
| 33 |
|
| 34 |
int main () |
| 35 |
{ |
| 36 |
uint16_t crc = 0x0D80; |
| 37 |
for (uint8_t i = 0; i < 255; i++) |
| 38 |
{ |
| 39 |
uint16_t res1 = crc_xmodem_update_O0 (i, crc); |
| 40 |
uint16_t res2 = crc_xmodem_update (i, crc); |
| 41 |
if (res1 != res2) |
| 42 |
__builtin_abort (); |
| 43 |
crc = res1; |
| 44 |
} |
| 45 |
__builtin_exit (0); |
| 46 |
} |
| 47 |
/* { dg-final { scan-tree-dump "crc_xmodem_update function maybe contains CRC calculation." "crc"} } */ |
| 48 |
/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc"} } */ |
| 49 |
/* { dg-final { scan-tree-dump "Bit forward" "crc"} } */ |
| 50 |
/* { dg-final { scan-tree-dump "calculates CRC!" "crc"} } */ |
| 51 |
/* { dg-final { scan-tree-dump "Polynomial's value is \\\{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1\\\}" "crc"} } */ |
| 52 |
/* { dg-final { scan-tree-dump-times "Couldn't generate faster CRC code." 0 "crc"} } */ |