Skip to content
Permalink
Browse files
MDEV-23585: Fix HAVE_CLMUL_INSTRUCTION
MDEV-22641 in commit dec3f8c
refactored a SIMD implementation of CRC-32 for the ISO 3309 polynomial
that uses the IA-32/AMD64 carry-less multiplication (pclmul)
instructions. The code was previously only available in Mariabackup;
it was changed to be a general replacement of the zlib crc32().

There exist AMD64 systems where CMAKE_SYSTEM_PROCESSOR matches
the pattern i[36]86 but not x86_64 or amd64. This would cause a
link failure, because mysys/checksum.c would basically assume that
the compiler support for instruction is always available on GCC-compatible
compilers on AMD64.

Furthermore, we were unnecessarily disabling the SIMD acceleration
for 32-bit executables.

Note: Until MDEV-22749 has been implemented, the PCLMUL instruction
will not be used on Microsoft Windows.

Closes: #1660
  • Loading branch information
dr-m committed Aug 27, 2020
1 parent bb284e3 commit b47d61d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 6 deletions.
@@ -102,6 +102,8 @@
/* Libraries */
#cmakedefine HAVE_LIBWRAP 1
#cmakedefine HAVE_SYSTEMD 1

#cmakedefine HAVE_CLMUL_INSTRUCTION 1
#cmakedefine HAVE_CRC32_VPMSUM 1

/* Support ARMv8 crc + crypto */
@@ -58,7 +58,7 @@ IF (WIN32)
my_win_popen.cc)
ENDIF()

IF(NOT MSVC AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64")
IF(NOT MSVC AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|i[36]86")
#Check for PCLMUL instruction (x86)
CHECK_C_SOURCE_COMPILES("
int main()
@@ -30,8 +30,7 @@ static unsigned int my_crc32_zlib(unsigned int crc, const void *data,
my_crc32_t my_checksum= my_crc32_zlib;
#endif

#if __GNUC__ >= 4 && defined(__x86_64__)

#ifdef HAVE_CLMUL_INSTRUCTION
extern int crc32_pclmul_enabled();
extern unsigned int crc32_pclmul(unsigned int, const void *, size_t);

@@ -57,8 +57,6 @@ typedef uint8_t byte;

# define _gcry_bswap32 __builtin_bswap32

#if __GNUC__ >= 4 && defined(__x86_64__)

#if defined(_GCRY_GCC_VERSION) && _GCRY_GCC_VERSION >= 40400 /* 4.4 */
/* Prevent compiler from issuing SSE instructions between asm blocks. */
# pragma GCC target("no-sse")
@@ -542,4 +540,3 @@ unsigned int crc32_pclmul(unsigned int crc32, const void *buf, size_t len)
crc32_intel_pclmul(&crc32, buf, len);
return ~crc32;
}
#endif

0 comments on commit b47d61d

Please sign in to comment.