PostgreSQL Source Code  git master
pg_crc32c.h File Reference
#include "port/pg_bswap.h"
Include dependency graph for pg_crc32c.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define INIT_CRC32C(crc)   ((crc) = 0xFFFFFFFF)
 
#define EQ_CRC32C(c1, c2)   ((c1) == (c2))
 
#define COMP_CRC32C(crc, data, len)    ((crc) = pg_comp_crc32c_sb8((crc), (data), (len)))
 
#define FIN_CRC32C(crc)   ((crc) ^= 0xFFFFFFFF)
 

Typedefs

typedef uint32 pg_crc32c
 

Functions

pg_crc32c pg_comp_crc32c_sb8 (pg_crc32c crc, const void *data, size_t len)
 

Macro Definition Documentation

◆ COMP_CRC32C

#define COMP_CRC32C (   crc,
  data,
  len 
)     ((crc) = pg_comp_crc32c_sb8((crc), (data), (len)))

Definition at line 98 of file pg_crc32c.h.

◆ EQ_CRC32C

#define EQ_CRC32C (   c1,
  c2 
)    ((c1) == (c2))

Definition at line 42 of file pg_crc32c.h.

◆ FIN_CRC32C

#define FIN_CRC32C (   crc)    ((crc) ^= 0xFFFFFFFF)

Definition at line 103 of file pg_crc32c.h.

◆ INIT_CRC32C

#define INIT_CRC32C (   crc)    ((crc) = 0xFFFFFFFF)

Definition at line 41 of file pg_crc32c.h.

Typedef Documentation

◆ pg_crc32c

typedef uint32 pg_crc32c

Definition at line 38 of file pg_crc32c.h.

Function Documentation

◆ pg_comp_crc32c_sb8()

pg_crc32c pg_comp_crc32c_sb8 ( pg_crc32c  crc,
const void *  data,
size_t  len 
)

Definition at line 35 of file pg_crc32c_sb8.c.

36 {
37  const unsigned char *p = data;
38  const uint32 *p4;
39 
40  /*
41  * Handle 0-3 initial bytes one at a time, so that the loop below starts
42  * with a pointer aligned to four bytes.
43  */
44  while (len > 0 && ((uintptr_t) p & 3))
45  {
46  crc = CRC8(*p++);
47  len--;
48  }
49 
50  /*
51  * Process eight bytes of data at a time.
52  */
53  p4 = (const uint32 *) p;
54  while (len >= 8)
55  {
56  uint32 a = *p4++ ^ crc;
57  uint32 b = *p4++;
58 
59 #ifdef WORDS_BIGENDIAN
60  const uint8 c0 = b;
61  const uint8 c1 = b >> 8;
62  const uint8 c2 = b >> 16;
63  const uint8 c3 = b >> 24;
64  const uint8 c4 = a;
65  const uint8 c5 = a >> 8;
66  const uint8 c6 = a >> 16;
67  const uint8 c7 = a >> 24;
68 #else
69  const uint8 c0 = b >> 24;
70  const uint8 c1 = b >> 16;
71  const uint8 c2 = b >> 8;
72  const uint8 c3 = b;
73  const uint8 c4 = a >> 24;
74  const uint8 c5 = a >> 16;
75  const uint8 c6 = a >> 8;
76  const uint8 c7 = a;
77 #endif
78 
79  crc =
80  pg_crc32c_table[0][c0] ^ pg_crc32c_table[1][c1] ^
81  pg_crc32c_table[2][c2] ^ pg_crc32c_table[3][c3] ^
82  pg_crc32c_table[4][c4] ^ pg_crc32c_table[5][c5] ^
83  pg_crc32c_table[6][c6] ^ pg_crc32c_table[7][c7];
84 
85  len -= 8;
86  }
87 
88  /*
89  * Handle any remaining bytes one at a time.
90  */
91  p = (const unsigned char *) p4;
92  while (len > 0)
93  {
94  crc = CRC8(*p++);
95  len--;
96  }
97 
98  return crc;
99 }
uint8_t uint8
Definition: c.h:483
uint32_t uint32
Definition: c.h:485
int b
Definition: isn.c:69
int a
Definition: isn.c:68
static const uint32 pg_crc32c_table[8][256]
Definition: pg_crc32c_sb8.c:25
#define CRC8(x)
Definition: pg_crc32c_sb8.c:31
const void size_t len
const void * data
return crc

References a, b, crc, CRC8, data, len, and pg_crc32c_table.

Referenced by pg_comp_crc32c_choose().