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

Go to the source code of this file.

Functions

 pg_attribute_no_sanitize_alignment ()
 

Function Documentation

◆ pg_attribute_no_sanitize_alignment()

pg_attribute_no_sanitize_alignment ( )

Definition at line 21 of file pg_crc32c_sse42.c.

24 {
25  const unsigned char *p = data;
26  const unsigned char *pend = p + len;
27 
28  /*
29  * Process eight bytes of data at a time.
30  *
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.
34  */
35 #ifdef __x86_64__
36  while (p + 8 <= pend)
37  {
38  crc = (uint32) _mm_crc32_u64(crc, *((const uint64 *) p));
39  p += 8;
40  }
41 
42  /* Process remaining full four bytes if any */
43  if (p + 4 <= pend)
44  {
45  crc = _mm_crc32_u32(crc, *((const unsigned int *) p));
46  p += 4;
47  }
48 #else
49 
50  /*
51  * Process four bytes at a time. (The eight byte instruction is not
52  * available on the 32-bit x86 architecture).
53  */
54  while (p + 4 <= pend)
55  {
56  crc = _mm_crc32_u32(crc, *((const unsigned int *) p));
57  p += 4;
58  }
59 #endif /* __x86_64__ */
60 
61  /* Process any remaining bytes one at a time. */
62  while (p < pend)
63  {
64  crc = _mm_crc32_u8(crc, *p);
65  p++;
66  }
67 
68  return crc;
69 }
unsigned int uint32
Definition: c.h:441