aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/torture/crc-side-instr-5.c
blob: 0af1adfa6c3d2ad2b5cb6115f4398a8308552233 (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
/* { dg-do compile } */
/* { dg-options "-fdump-tree-crc-details" } */
/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */

#include <stdint.h>

uint16_t crc16_update(uint16_t crc, uint8_t a) {
  int i;
  uint16_t b;
  for (i = 0; i < 8; ++i) {
      if ((crc & 1) ^ (a & 1))
	crc = (crc >> 1) ^ 0xa001;
      else
	crc = (crc >> 1);
      a >>= 1;
      b = crc; // In compiled version, b is outside of the loop.
    }
  uint16_t c = ++b;
  return c;
}

/* { dg-final { scan-tree-dump "crc16_update function maybe contains CRC calculation." "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 "calculates CRC!" "crc" } } */
/* { dg-final { scan-tree-dump "Polynomial's value is \\\{1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1\\\}" "crc" } } */