aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/crc-5.c
blob: 438521627e2523c65c5f77313da21c2c18f19773 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-crc-details" } */

typedef unsigned short ee_u16;
typedef unsigned char ee_u8;

ee_u16 crcu8(ee_u8 data, ee_u16 crc) {
    ee_u8 i = 0, x16 = 0, carry = 0;
    for (i = 0; i < 8; i++) {
        x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1));
        data >>= 1;
        if (x16 == 1) {
            crc ^= 0x4002;
            carry = 1;
        } else
            carry = 0;
        crc >>= 1;
        if (carry)
            crc |= 0x8000;
        else
            crc &= 0x7fff;
    }
    return crc;
}
/* { dg-final { scan-tree-dump "crcu8 function maybe calculates CRC and returns it." "crc"} } */
/* { dg-final { scan-tree-dump "Return size is 16" "crc"} } */
/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc"} } */
/* { dg-final { scan-tree-dump "Bit reversed" "crc"} } */
/* { dg-final { scan-tree-dump "Executing \[a-zA-Z_\]\[a-zA-Z0-9_\]* = \[a-zA-Z_\]\[a-zA-Z0-9_\]* \\\^ \[a-zA-Z0-9_\]+\(\\\(\[a-zA-Z\]\\\)\)?;" "crc" } } */
/* { dg-final { scan-tree-dump "Executing \[a-zA-Z_\]\[a-zA-Z0-9_\]* = \[a-zA-Z_\]\[a-zA-Z0-9_\]* \(<<|>>\) \[0-9]+;" "crc" } } */
/* { dg-final { scan-tree-dump "crcu8 function calculates CRC!" "crc"} } */
/* { dg-final { scan-tree-dump "Return value is \\\{1, \[a-zA-Z0-9_\]+\(\\\(\[a-zA-Z\]\\\)\)?\\\[15\\\], \\\(\[a-zA-Z0-9_\]+\(\\\(\[a-zA-Z\]\\\)\)?\\\[14\\\] \\\^ 1\\\), \[a-zA-Z0-9_\]+\(\\\(\[a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