Debian Codegraph @

gcc/testsuite/gcc.dg/crc-from-fedora-packages-23.c

raw
1 /* { dg-do compile } */
2 /* { dg-options "-fdump-tree-crc-details -O2" } */
3
4 // File - ModbusComm.ii
5
6 #include <stdint.h>
7 uint16_t ModbusCrc(const uint8_t *data, unsigned int sz)
8 {
9 static const uint16_t MODBUS_CRC_POLY = 0xA001;
10 uint16_t crc = 0xffff;
11
12 while (sz--)
13 {
14 crc ^= *data++;
15 for (unsigned int i = 0; i < 8; ++i)
16 {
17 if (crc & 0x1)
18 crc = (crc >> 1) ^ MODBUS_CRC_POLY;
19 else
20 crc >>= 1;
21 }
22 }
23
24 return crc;
25 }
26
27 /* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */