Improve notation of BuiltinTrancheNames
[pgsql.git] / src / port / pg_crc32c_sse42.c
blob7f88c1148009b11205807e93b8dc7ac7dcd2d746
1 /*-------------------------------------------------------------------------
3 * pg_crc32c_sse42.c
4 * Compute CRC-32C checksum using Intel SSE 4.2 instructions.
6 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
10 * IDENTIFICATION
11 * src/port/pg_crc32c_sse42.c
13 *-------------------------------------------------------------------------
15 #include "c.h"
17 #include <nmmintrin.h>
19 #include "port/pg_crc32c.h"
21 pg_attribute_no_sanitize_alignment()
22 pg_crc32c
23 pg_comp_crc32c_sse42(pg_crc32c crc, const void *data, size_t len)
25 const unsigned char *p = data;
26 const unsigned char *pend = p + len;
29 * Process eight bytes of data at a time.
31 * NB: We do unaligned accesses here. The Intel architecture allows that,
32 * and performance testing didn't show any performance gain from aligning
33 * the begin address.
35 #ifdef __x86_64__
36 while (p + 8 <= pend)
38 crc = (uint32) _mm_crc32_u64(crc, *((const uint64 *) p));
39 p += 8;
42 /* Process remaining full four bytes if any */
43 if (p + 4 <= pend)
45 crc = _mm_crc32_u32(crc, *((const unsigned int *) p));
46 p += 4;
48 #else
51 * Process four bytes at a time. (The eight byte instruction is not
52 * available on the 32-bit x86 architecture).
54 while (p + 4 <= pend)
56 crc = _mm_crc32_u32(crc, *((const unsigned int *) p));
57 p += 4;
59 #endif /* __x86_64__ */
61 /* Process any remaining bytes one at a time. */
62 while (p < pend)
64 crc = _mm_crc32_u8(crc, *p);
65 p++;
68 return crc;