aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/crc-25.c
blob: 96add9e70fd6ca4c12b526b36634d8b3acabe7f3 (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
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-crc-details" } */

#include <stdint.h>

typedef uint8_t crc;
#define WIDTH (8 * sizeof(crc))
#define TOPBIT (1 << (WIDTH - 1))

crc
crcSlow(uint8_t message) {
  crc remainder = 0;
      remainder ^= (message << (WIDTH - 8));
      for (uint8_t bit = 8; bit > 0; --bit) {
	  if (remainder & TOPBIT) {
	      remainder = (remainder << 1) ^ 1234;
	    } else {
	      remainder = (remainder << 1);
	    }
	}
  return (remainder);
}

/* { dg-final { scan-tree-dump "crcSlow function maybe calculates CRC and returns it." "crc"} } */
/* { dg-final { scan-tree-dump "Return size is 8" "crc"} } */
/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc"} } */
/* { dg-final { scan-tree-dump "Bit forward" "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 "crcSlow function calculates CRC." "crc"} } */