PostgreSQL Source Code  git master
pg_crc32c_armv8.c File Reference
#include "c.h"
#include "port/pg_crc32c.h"
#include <arm_acle.h>
Include dependency graph for pg_crc32c_armv8.c:

Go to the source code of this file.

Functions

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

Function Documentation

◆ pg_comp_crc32c_armv8()

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

Definition at line 22 of file pg_crc32c_armv8.c.

References PointerIsAligned.

Referenced by pg_comp_crc32c_choose(), and pg_crc32c_armv8_available().

23 {
24  const unsigned char *p = data;
25  const unsigned char *pend = p + len;
26 
27  /*
28  * ARMv8 doesn't require alignment, but aligned memory access is
29  * significantly faster. Process leading bytes so that the loop below
30  * starts with a pointer aligned to eight bytes.
31  */
32  if (!PointerIsAligned(p, uint16) &&
33  p + 1 <= pend)
34  {
35  crc = __crc32cb(crc, *p);
36  p += 1;
37  }
38  if (!PointerIsAligned(p, uint32) &&
39  p + 2 <= pend)
40  {
41  crc = __crc32ch(crc, *(uint16 *) p);
42  p += 2;
43  }
44  if (!PointerIsAligned(p, uint64) &&
45  p + 4 <= pend)
46  {
47  crc = __crc32cw(crc, *(uint32 *) p);
48  p += 4;
49  }
50 
51  /* Process eight bytes at a time, as far as we can. */
52  while (p + 8 <= pend)
53  {
54  crc = __crc32cd(crc, *(uint64 *) p);
55  p += 8;
56  }
57 
58  /* Process remaining 0-7 bytes. */
59  if (p + 4 <= pend)
60  {
61  crc = __crc32cw(crc, *(uint32 *) p);
62  p += 4;
63  }
64  if (p + 2 <= pend)
65  {
66  crc = __crc32ch(crc, *(uint16 *) p);
67  p += 2;
68  }
69  if (p < pend)
70  {
71  crc = __crc32cb(crc, *p);
72  }
73 
74  return crc;
75 }
unsigned short uint16
Definition: c.h:357
unsigned int uint32
Definition: c.h:358
#define PointerIsAligned(pointer, type)
Definition: c.h:632