PostgreSQL Source Code git master
pg_crc32c_armv8.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * pg_crc32c_armv8.c
4 * Compute CRC-32C checksum using ARMv8 CRC Extension instructions
5 *
6 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 *
10 * IDENTIFICATION
11 * src/port/pg_crc32c_armv8.c
12 *
13 *-------------------------------------------------------------------------
14 */
15#include "c.h"
16
17#ifdef _MSC_VER
18#include <intrin.h>
19#else
20#include <arm_acle.h>
21#endif
22
23#include "port/pg_crc32c.h"
24
27{
28 const unsigned char *p = data;
29 const unsigned char *pend = p + len;
30
31 /*
32 * ARMv8 doesn't require alignment, but aligned memory access is
33 * significantly faster. Process leading bytes so that the loop below
34 * starts with a pointer aligned to eight bytes.
35 */
36 if (!PointerIsAligned(p, uint16) &&
37 p + 1 <= pend)
38 {
39 crc = __crc32cb(crc, *p);
40 p += 1;
41 }
42 if (!PointerIsAligned(p, uint32) &&
43 p + 2 <= pend)
44 {
45 crc = __crc32ch(crc, *(uint16 *) p);
46 p += 2;
47 }
48 if (!PointerIsAligned(p, uint64) &&
49 p + 4 <= pend)
50 {
51 crc = __crc32cw(crc, *(uint32 *) p);
52 p += 4;
53 }
54
55 /* Process eight bytes at a time, as far as we can. */
56 while (p + 8 <= pend)
57 {
58 crc = __crc32cd(crc, *(uint64 *) p);
59 p += 8;
60 }
61
62 /* Process remaining 0-7 bytes. */
63 if (p + 4 <= pend)
64 {
65 crc = __crc32cw(crc, *(uint32 *) p);
66 p += 4;
67 }
68 if (p + 2 <= pend)
69 {
70 crc = __crc32ch(crc, *(uint16 *) p);
71 p += 2;
72 }
73 if (p < pend)
74 {
75 crc = __crc32cb(crc, *p);
76 }
77
78 return crc;
79}
#define PointerIsAligned(pointer, type)
Definition: c.h:788
uint64_t uint64
Definition: c.h:553
uint16_t uint16
Definition: c.h:551
uint32_t uint32
Definition: c.h:552
uint32 pg_crc32c
Definition: pg_crc32c.h:38
pg_crc32c pg_comp_crc32c_armv8(pg_crc32c crc, const void *data, size_t len)
const void size_t len
const void * data
return crc
const unsigned char * pend