Debian Codegraph @

gcc/testsuite/gcc.dg/torture/crc-linux-4.c

raw
1 /* { dg-do compile } */
2 /* { dg-options "-fdump-tree-crc-details -w" } */
3 /* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */
4
5 /* We don't detect, it's optimized to branch-less CRC. */
6 #define CRC32_POLY_LE 0xedb88320
7 typedef unsigned int u32;
8 u32 calc_crc(unsigned char *buf, int len)
9 {
10 u32 reg;
11 u32 tmp;
12 int j, k;
13
14 reg = 0xffffffff;
15
16 for (j = 0; j < len; j++) {
17 reg ^= buf[j];
18
19 for (k = 0; k < 8; k++) {
20 tmp = reg & 0x01;
21
22 reg >>= 1;
23
24 if (tmp)
25 reg ^= CRC32_POLY_LE;
26 }
27 }
28
29 return ~reg;
30 }