Debian Codegraph @

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

raw
1 /* { dg-do compile } */
2 /* { dg-options "-fdump-tree-crc-details" } */
3 /* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */
4
5 #include <stddef.h>
6 #include <stdint.h>
7 /* We don't find, as we can't replace the first loop,
8 and in the second loop polynomials leading 1 bit is kept too
9 (second function's iteration count is 4). */
10 typedef unsigned char u8;
11 typedef unsigned short u16;
12 u8 drm_dp_msg_data_crc4(const uint8_t *data, u8 number_of_bytes)
13 {
14 u8 bitmask = 0x80;
15 u8 bitshift = 7;
16 u8 array_index = 0;
17 int number_of_bits = number_of_bytes * 8;
18 u16 remainder = 0;
19
20 while (number_of_bits != 0) {
21 number_of_bits--;
22 remainder <<= 1;
23 remainder |= (data[array_index] & bitmask) >> bitshift;
24 bitmask >>= 1;
25 bitshift--;
26 if (bitmask == 0) {
27 bitmask = 0x80;
28 bitshift = 7;
29 array_index++;
30 }
31 if ((remainder & 0x100) == 0x100)
32 remainder ^= 0xd5;
33 }
34
35 number_of_bits = 8;
36 while (number_of_bits != 0) {
37 number_of_bits--;
38 remainder <<= 1;
39 if ((remainder & 0x100) != 0)
40 remainder ^= 0xd5;
41 }
42
43 return remainder & 0xff;
44 }
45
46 /* sideband msg handling */
47 u8 drm_dp_msg_header_crc4(const uint8_t *data, size_t num_nibbles)
48 {
49 u8 bitmask = 0x80;
50 u8 bitshift = 7;
51 u8 array_index = 0;
52 int number_of_bits = num_nibbles * 4;
53 u8 remainder = 0;
54
55 while (number_of_bits != 0) {
56 number_of_bits--;
57 remainder <<= 1;
58 remainder |= (data[array_index] & bitmask) >> bitshift;
59 bitmask >>= 1;
60 bitshift--;
61 if (bitmask == 0) {
62 bitmask = 0x80;
63 bitshift = 7;
64 array_index++;
65 }
66 if ((remainder & 0x10) == 0x10)
67 remainder ^= 0x13;
68 }
69
70 number_of_bits = 4;
71 while (number_of_bits != 0) {
72 number_of_bits--;
73 remainder <<= 1;
74 if ((remainder & 0x10) != 0)
75 remainder ^= 0x13;
76 }
77
78 return remainder;
79 }
80
81 /* { dg-final { scan-tree-dump "drm_dp_msg_data_crc4 function maybe contains CRC calculation." "crc" } } */