PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_crc32c_sb8.c File Reference
#include "c.h"
#include "port/pg_crc32c.h"
Include dependency graph for pg_crc32c_sb8.c:

Go to the source code of this file.

Macros

#define CRC8(x)   pg_crc32c_table[0][(crc ^ (x)) & 0xFF] ^ (crc >> 8)
 

Functions

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

Variables

static const uint32 pg_crc32c_table [8][256]
 

Macro Definition Documentation

#define CRC8 (   x)    pg_crc32c_table[0][(crc ^ (x)) & 0xFF] ^ (crc >> 8)

Definition at line 31 of file pg_crc32c_sb8.c.

Referenced by pg_comp_crc32c_sb8().

Function Documentation

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.

References CRC8, and pg_crc32c_table.

Referenced by pg_comp_crc32c_choose().

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 }
unsigned char uint8
Definition: c.h:256
unsigned int uint32
Definition: c.h:258
static const uint32 pg_crc32c_table[8][256]
Definition: pg_crc32c_sb8.c:25
#define CRC8(x)
Definition: pg_crc32c_sb8.c:31

Variable Documentation

static const uint32 pg_crc32c_table
static

Definition at line 25 of file pg_crc32c_sb8.c.

Referenced by pg_comp_crc32c_sb8().