mightymandel v16

GPU-based Mandelbrot set explorer

crc.c
Go to the documentation of this file.
1 
20 /* Table of CRCs of all 8-bit messages. */
21 unsigned long crc_table[256];
22 
23 /* Flag: has the table been computed? Initially false. */
25 
26 /* Make the table for a fast CRC. */
27 void make_crc_table(void)
28 {
29  unsigned long c;
30  int n, k;
31 
32  for (n = 0; n < 256; n++) {
33  c = (unsigned long) n;
34  for (k = 0; k < 8; k++) {
35  if (c & 1)
36  c = 0xedb88320L ^ (c >> 1);
37  else
38  c = c >> 1;
39  }
40  crc_table[n] = c;
41  }
43 }
44 
45 
46 /* Update a running CRC with the bytes buf[0..len-1]--the CRC
47  should be initialized to all 1's, and the transmitted value
48  is the 1's complement of the final running CRC (see the
49  crc() routine below). */
50 
51 /* {{{ modified by Claude Heiland-Allen 2015-01-08 (added const) */
52 unsigned long update_crc(unsigned long crc, const unsigned char *buf,
53 /* }}} modified by Claude Heiland-Allen 2015-01-08 (added const) */
54  int len)
55 {
56  unsigned long c = crc;
57  int n;
58 
59  if (!crc_table_computed)
61  for (n = 0; n < len; n++) {
62  c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
63  }
64  return c;
65 }
66 
67 /* Return the CRC of the bytes buf[0..len-1]. */
68 /* {{{ modified by Claude Heiland-Allen 2015-01-08 (added const) */
69 unsigned long crc(const unsigned char *buf, int len)
70 /* }}} modified by Claude Heiland-Allen 2015-01-08 (added const) */
71 {
72  return update_crc(0xffffffffL, buf, len) ^ 0xffffffffL;
73 }