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

Go to the source code of this file.

Functions

static bool zmm_regs_available (void)
 
static pg_crc32c pg_comp_crc32c_choose (pg_crc32c crc, const void *data, size_t len)
 

Variables

pg_crc32c(* pg_comp_crc32c )(pg_crc32c crc, const void *data, size_t len) = pg_comp_crc32c_choose
 

Function Documentation

◆ pg_comp_crc32c_choose()

static pg_crc32c pg_comp_crc32c_choose ( pg_crc32c  crc,
const void *  data,
size_t  len 
)
static

Definition at line 61 of file pg_crc32c_sse42_choose.c.

62{
63 unsigned int exx[4] = {0, 0, 0, 0};
64
65 /*
66 * Set fallback. We must guard since slicing-by-8 is not visible
67 * everywhere.
68 */
69#ifdef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK
71#endif
72
73#if defined(HAVE__GET_CPUID)
74 __get_cpuid(1, &exx[0], &exx[1], &exx[2], &exx[3]);
75#elif defined(HAVE__CPUID)
76 __cpuid(exx, 1);
77#else
78#error cpuid instruction not available
79#endif
80
81 if ((exx[2] & (1 << 20)) != 0) /* SSE 4.2 */
82 {
83 pg_comp_crc32c = pg_comp_crc32c_sse42;
84
85 if (exx[2] & (1 << 27) && /* OSXSAVE */
87 {
88 /* second cpuid call on leaf 7 to check extended AVX-512 support */
89
90 memset(exx, 0, 4 * sizeof(exx[0]));
91
92#if defined(HAVE__GET_CPUID_COUNT)
93 __get_cpuid_count(7, 0, &exx[0], &exx[1], &exx[2], &exx[3]);
94#elif defined(HAVE__CPUIDEX)
95 __cpuidex(exx, 7, 0);
96#endif
97
98#ifdef USE_AVX512_CRC32C_WITH_RUNTIME_CHECK
99 if (exx[2] & (1 << 10) && /* VPCLMULQDQ */
100 exx[1] & (1 << 31)) /* AVX512-VL */
101 pg_comp_crc32c = pg_comp_crc32c_avx512;
102#endif
103 }
104 }
105
106 return pg_comp_crc32c(crc, data, len);
107}
pg_crc32c pg_comp_crc32c_sb8(pg_crc32c crc, const void *data, size_t len)
Definition: pg_crc32c_sb8.c:35
const void size_t len
const void * data
return crc
static bool zmm_regs_available(void)
pg_crc32c(* pg_comp_crc32c)(pg_crc32c crc, const void *data, size_t len)

References crc, data, len, pg_comp_crc32c, pg_comp_crc32c_sb8(), and zmm_regs_available().

◆ zmm_regs_available()

static bool zmm_regs_available ( void  )
static

Definition at line 47 of file pg_crc32c_sse42_choose.c.

48{
49#ifdef HAVE_XSAVE_INTRINSICS
50 return (_xgetbv(0) & 0xe6) == 0xe6;
51#else
52 return false;
53#endif
54}

Referenced by pg_comp_crc32c_choose().

Variable Documentation

◆ pg_comp_crc32c

pg_crc32c(* pg_comp_crc32c) (pg_crc32c crc, const void *data, size_t len) ( pg_crc32c  crc,
const void *  data,
size_t  len 
) = pg_comp_crc32c_choose

Definition at line 109 of file pg_crc32c_sse42_choose.c.

Referenced by pg_comp_crc32c_choose().