Commit ccbe6bb6 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-19935 Create unified CRC-32 interface

Add CRC32C code to mysys. The x86-64 implementation uses PCMULQDQ in addition to CRC32 instruction
after Intel whitepaper, and is ported from rocksdb code.

Optimized ARM and POWER CRC32 were already present in mysys.
parent ab56cbcd
...@@ -103,15 +103,6 @@ ...@@ -103,15 +103,6 @@
#cmakedefine HAVE_LIBWRAP 1 #cmakedefine HAVE_LIBWRAP 1
#cmakedefine HAVE_SYSTEMD 1 #cmakedefine HAVE_SYSTEMD 1
#cmakedefine HAVE_CPUID_INSTRUCTION 1
#cmakedefine HAVE_CLMUL_INSTRUCTION 1
#cmakedefine HAVE_CRC32_VPMSUM 1
/* Support ARMv8 crc + crypto */
#cmakedefine HAVE_ARMV8_CRC 1
#cmakedefine HAVE_ARMV8_CRYPTO 1
#cmakedefine HAVE_ARMV8_CRC_CRYPTO_INTRINSICS 1
/* Does "struct timespec" have a "sec" and "nsec" field? */ /* Does "struct timespec" have a "sec" and "nsec" field? */
#cmakedefine HAVE_TIMESPEC_TS_SEC 1 #cmakedefine HAVE_TIMESPEC_TS_SEC 1
......
...@@ -73,20 +73,8 @@ IF(WITH_INNOBASE_STORAGE_ENGINE) ...@@ -73,20 +73,8 @@ IF(WITH_INNOBASE_STORAGE_ENGINE)
# We use the InnoDB code directly in case the code changes. # We use the InnoDB code directly in case the code changes.
ADD_DEFINITIONS("-DUNIV_INNOCHECKSUM") ADD_DEFINITIONS("-DUNIV_INNOCHECKSUM")
# Avoid generating Hardware Capabilities due to crc32 instructions
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND CMAKE_SYSTEM_PROCESSOR MATCHES "i386")
MY_CHECK_CXX_COMPILER_FLAG("-Wa,-nH")
IF(have_CXX__Wa__nH)
ADD_COMPILE_FLAGS(
../storage/innobase/ut/ut0crc32.cc
COMPILE_FLAGS "-Wa,-nH"
)
ENDIF()
ENDIF()
SET(INNOBASE_SOURCES SET(INNOBASE_SOURCES
../storage/innobase/buf/buf0checksum.cc ../storage/innobase/buf/buf0checksum.cc
../storage/innobase/ut/ut0crc32.cc
../storage/innobase/ut/ut0ut.cc ../storage/innobase/ut/ut0ut.cc
../storage/innobase/buf/buf0buf.cc ../storage/innobase/buf/buf0buf.cc
../storage/innobase/page/page0zip.cc ../storage/innobase/page/page0zip.cc
......
...@@ -1583,7 +1583,6 @@ int main( ...@@ -1583,7 +1583,6 @@ int main(
/* enable when space_id of given file is zero. */ /* enable when space_id of given file is zero. */
bool is_system_tablespace = false; bool is_system_tablespace = false;
ut_crc32_init();
MY_INIT(argv[0]); MY_INIT(argv[0]);
DBUG_ENTER("main"); DBUG_ENTER("main");
DBUG_PROCESS(argv[0]); DBUG_PROCESS(argv[0]);
......
...@@ -1833,7 +1833,6 @@ copy_back() ...@@ -1833,7 +1833,6 @@ copy_back()
srv_max_n_threads = 1000; srv_max_n_threads = 1000;
sync_check_init(); sync_check_init();
ut_crc32_init();
/* copy undo tablespaces */ /* copy undo tablespaces */
......
...@@ -97,8 +97,6 @@ main(int argc, char **argv) ...@@ -97,8 +97,6 @@ main(int argc, char **argv)
{ {
MY_INIT(argv[0]); MY_INIT(argv[0]);
my_checksum_init();
if (get_options(&argc, &argv)) { if (get_options(&argc, &argv)) {
goto err; goto err;
} }
......
...@@ -4011,9 +4011,6 @@ static bool xtrabackup_backup_func() ...@@ -4011,9 +4011,6 @@ static bool xtrabackup_backup_func()
ut_d(sync_check_enable()); ut_d(sync_check_enable());
/* Reset the system variables in the recovery module. */ /* Reset the system variables in the recovery module. */
trx_pool_init(); trx_pool_init();
ut_crc32_init();
my_checksum_init();
recv_sys.create(); recv_sys.create();
#ifdef WITH_INNODB_DISALLOW_WRITES #ifdef WITH_INNODB_DISALLOW_WRITES
...@@ -5386,7 +5383,6 @@ static bool xtrabackup_prepare_func(char** argv) ...@@ -5386,7 +5383,6 @@ static bool xtrabackup_prepare_func(char** argv)
sync_check_init(); sync_check_init();
ut_d(sync_check_enable()); ut_d(sync_check_enable());
ut_crc32_init();
recv_sys.create(); recv_sys.create();
log_sys.create(); log_sys.create();
recv_sys.recovery_on = true; recv_sys.recovery_on = true;
......
...@@ -901,18 +901,10 @@ extern int my_compress_buffer(uchar *dest, size_t *destLen, ...@@ -901,18 +901,10 @@ extern int my_compress_buffer(uchar *dest, size_t *destLen,
extern int packfrm(const uchar *, size_t, uchar **, size_t *); extern int packfrm(const uchar *, size_t, uchar **, size_t *);
extern int unpackfrm(uchar **, size_t *, const uchar *); extern int unpackfrm(uchar **, size_t *, const uchar *);
void my_checksum_init(void); extern uint32 my_checksum(uint32, const void *, size_t);
#ifdef HAVE_CRC32_VPMSUM extern uint32 my_crc32c(uint32, const void *, size_t);
extern ha_checksum my_checksum(ha_checksum, const void *, size_t);
#else
typedef ha_checksum (*my_crc32_t)(ha_checksum, const void *, size_t);
extern MYSQL_PLUGIN_IMPORT my_crc32_t my_checksum;
#endif
#if defined(__GNUC__) && defined(HAVE_ARMV8_CRC) extern const char *my_crc32c_implementation();
int crc32_aarch64_available(void);
const char *crc32c_aarch64_available(void);
#endif
#ifdef DBUG_ASSERT_EXISTS #ifdef DBUG_ASSERT_EXISTS
extern void my_debug_put_break_here(void); extern void my_debug_put_break_here(void);
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/mysys) INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/mysys)
SET(MYSYS_SOURCES array.c charset-def.c charset.c checksum.c my_default.c SET(MYSYS_SOURCES array.c charset-def.c charset.c crc32ieee.cc my_default.c
get_password.c get_password.c
errors.c hash.c list.c errors.c hash.c list.c
mf_cache.c mf_dirname.c mf_fn_ext.c mf_cache.c mf_dirname.c mf_fn_ext.c
...@@ -45,7 +45,7 @@ SET(MYSYS_SOURCES array.c charset-def.c charset.c checksum.c my_default.c ...@@ -45,7 +45,7 @@ SET(MYSYS_SOURCES array.c charset-def.c charset.c checksum.c my_default.c
my_uuid.c wqueue.c waiting_threads.c ma_dyncol.c ../sql-common/my_time.c my_uuid.c wqueue.c waiting_threads.c ma_dyncol.c ../sql-common/my_time.c
my_rdtsc.c my_context.c psi_noop.c my_rdtsc.c my_context.c psi_noop.c
my_atomic_writes.c my_cpu.c my_likely.c my_largepage.c my_atomic_writes.c my_cpu.c my_likely.c my_largepage.c
file_logger.c my_dlerror.c) file_logger.c my_dlerror.c crc32/crc32c.cc)
IF (WIN32) IF (WIN32)
SET (MYSYS_SOURCES ${MYSYS_SOURCES} SET (MYSYS_SOURCES ${MYSYS_SOURCES}
...@@ -59,25 +59,23 @@ IF (WIN32) ...@@ -59,25 +59,23 @@ IF (WIN32)
ENDIF() ENDIF()
IF(MSVC) IF(MSVC)
SET(HAVE_CPUID_INSTRUCTION 1 CACHE BOOL "")
SET(HAVE_CLMUL_INSTRUCTION 1 CACHE BOOL "")
SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_x86.c) SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_x86.c)
ADD_DEFINITIONS(-DHAVE_SSE42 -DHAVE_PCLMUL)
IF(CLANG_CL) IF(CLANG_CL)
SET_SOURCE_FILES_PROPERTIES(crc32/crc32_x86.c PROPERTIES COMPILE_FLAGS "-msse4.2 -mpclmul") SET_SOURCE_FILES_PROPERTIES(crc32/crc32_x86.cc crc32/crc32c.c PROPERTIES COMPILE_FLAGS "-msse4.2 -mpclmul")
ENDIF() ENDIF()
ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|i386|i686") ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|i386|i686")
SET(HAVE_CPUID_INSTRUCTION 1 CACHE BOOL "")
MY_CHECK_C_COMPILER_FLAG(-msse4.2) MY_CHECK_C_COMPILER_FLAG(-msse4.2)
MY_CHECK_C_COMPILER_FLAG(-mpclmul) MY_CHECK_C_COMPILER_FLAG(-mpclmul)
CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H) CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
CHECK_INCLUDE_FILE(x86intrin.h HAVE_X86INTRIN_H) CHECK_INCLUDE_FILE(x86intrin.h HAVE_X86INTRIN_H)
IF(have_C__msse4.2 AND have_C__mpclmul AND HAVE_CPUID_H AND HAVE_X86INTRIN_H) IF(have_C__msse4.2 AND have_C__mpclmul AND HAVE_CPUID_H AND HAVE_X86INTRIN_H)
SET(HAVE_CLMUL_INSTRUCTION 1 CACHE BOOL "")
SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_x86.c) SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_x86.c)
SET_SOURCE_FILES_PROPERTIES(crc32/crc32_x86.c PROPERTIES COMPILE_FLAGS "-msse4.2 -mpclmul") SET_SOURCE_FILES_PROPERTIES(crc32/crc32_x86.c crc32/crc32c.cc PROPERTIES COMPILE_FLAGS "-msse4.2 -mpclmul")
ADD_DEFINITIONS(-DHAVE_SSE42 -DHAVE_PCLMUL)
ENDIF() ENDIF()
ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64") ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64")
IF(CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1) IF(CMAKE_COMPILER_IS_GNUCC)
include(CheckCXXSourceCompiles) include(CheckCXXSourceCompiles)
CHECK_CXX_SOURCE_COMPILES(" CHECK_CXX_SOURCE_COMPILES("
...@@ -99,23 +97,29 @@ ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64") ...@@ -99,23 +97,29 @@ ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64")
#include <sys/auxv.h> #include <sys/auxv.h>
int main() { foo(0); getauxval(AT_HWCAP); }" HAVE_ARMV8_CRYPTO) int main() { foo(0); getauxval(AT_HWCAP); }" HAVE_ARMV8_CRYPTO)
CHECK_C_COMPILER_FLAG(-march=armv8-a+crc+crypto HAVE_ARMV8_CRC_CRYPTO_INTRINSICS) CHECK_C_COMPILER_FLAG(-march=armv8-a+crc+crypto HAVE_ARMV8_CRC_CRYPTO_MARCH)
IF(HAVE_ARMV8_CRC_CRYPTO_INTRINSICS)
IF(HAVE_ARMV8_CRC_CRYPTO_MARCH)
CHECK_INCLUDE_FILE(arm_acle.h HAVE_ARM_ACLE_H -march=armv8-a+crc+crypto)
IF(HAVE_ARM_ACLE_H)
ADD_DEFINITIONS(-DHAVE_ARMV8_CRC_CRYPTO_INTRINSICS)
ENDIF()
IF(HAVE_ARMV8_CRC)
ADD_DEFINITIONS(-DHAVE_ARMV8_CRC)
ENDIF()
IF(HAVE_ARMV8_CRYPTO)
ADD_DEFINITIONS(-DHAVE_ARMV8_CRYPTO)
ENDIF()
SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_arm64.c) SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_arm64.c)
SET_SOURCE_FILES_PROPERTIES(crc32/crc32_arm64.c PROPERTIES SET_SOURCE_FILES_PROPERTIES(crc32/crc32_arm64.c PROPERTIES
COMPILE_FLAGS "-march=armv8-a+crc+crypto") COMPILE_FLAGS "-march=armv8-a+crc+crypto")
ENDIF() ENDIF()
ENDIF() ENDIF()
ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64") ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64")
SET(HAVE_CRC32_VPMSUM 1 PARENT_SCOPE) SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_ppc64.c crc32/crc32c_ppc.c)
SET(MYSYS_SOURCES ${MYSYS_SOURCES} $<TARGET_OBJECTS:crc32c> $<TARGET_OBJECTS:crc32ieee>) SET_SOURCE_FILES_PROPERTIES(crc32/crc32_ppc64.c crc32/crc32c_ppc.c PROPERTIES
COMPILE_FLAGS "${COMPILE_FLAGS} -maltivec -mvsx -mpower8-vector -mcrypto -mpower8-vector")
ADD_LIBRARY(crc32c OBJECT crc32/crc32_ppc64.c) ADD_DEFINITIONS(-DHAVE_POWER8 -DHAS_ALTIVEC)
ADD_LIBRARY(crc32ieee OBJECT crc32/crc32_ppc64.c)
SET_TARGET_PROPERTIES(crc32c crc32ieee PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -maltivec -mvsx -mpower8-vector -mcrypto -mpower8-vector")
SET_TARGET_PROPERTIES(crc32ieee PROPERTIES COMPILE_DEFINITIONS "CRC32_FUNCTION=my_checksum;CRC32_CONSTANTS_HEADER=\"pcc_crc32_constants.h\"")
SET_TARGET_PROPERTIES(crc32c PROPERTIES COMPILE_DEFINITIONS "CRC32_FUNCTION=crc32c_vpmsum;CRC32_CONSTANTS_HEADER=\"pcc_crc32c_constants.h\"")
ENDIF() ENDIF()
IF(UNIX) IF(UNIX)
......
...@@ -57,6 +57,12 @@ asm(".arch_extension crypto"); ...@@ -57,6 +57,12 @@ asm(".arch_extension crypto");
#define CRC32CH(crc, value) __asm__("crc32ch %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value)) #define CRC32CH(crc, value) __asm__("crc32ch %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value))
#define CRC32CB(crc, value) __asm__("crc32cb %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value)) #define CRC32CB(crc, value) __asm__("crc32cb %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value))
#define CRC32X(crc, value) __asm__("crc32x %w[c], %w[c], %x[v]":[c]"+r"(crc):[v]"r"(value))
#define CRC32W(crc, value) __asm__("crc32w %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value))
#define CRC32H(crc, value) __asm__("crc32h %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value))
#define CRC32B(crc, value) __asm__("crc32b %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value))
#define CRC32C3X8(buffer, ITR) \ #define CRC32C3X8(buffer, ITR) \
__asm__("crc32cx %w[c1], %w[c1], %x[v]":[c1]"+r"(crc1):[v]"r"(*((const uint64_t *)buffer + 42*1 + (ITR))));\ __asm__("crc32cx %w[c1], %w[c1], %x[v]":[c1]"+r"(crc1):[v]"r"(*((const uint64_t *)buffer + 42*1 + (ITR))));\
__asm__("crc32cx %w[c2], %w[c2], %x[v]":[c2]"+r"(crc2):[v]"r"(*((const uint64_t *)buffer + 42*2 + (ITR))));\ __asm__("crc32cx %w[c2], %w[c2], %x[v]":[c2]"+r"(crc2):[v]"r"(*((const uint64_t *)buffer + 42*2 + (ITR))));\
...@@ -73,6 +79,11 @@ asm(".arch_extension crypto"); ...@@ -73,6 +79,11 @@ asm(".arch_extension crypto");
#define CRC32CH(crc, value) (crc) = __crc32ch((crc), (value)) #define CRC32CH(crc, value) (crc) = __crc32ch((crc), (value))
#define CRC32CB(crc, value) (crc) = __crc32cb((crc), (value)) #define CRC32CB(crc, value) (crc) = __crc32cb((crc), (value))
#define CRC32X(crc, value) (crc) = __crc32d((crc), (value))
#define CRC32W(crc, value) (crc) = __crc32w((crc), (value))
#define CRC32H(crc, value) (crc) = __crc32h((crc), (value))
#define CRC32B(crc, value) (crc) = __crc32b((crc), (value))
#define CRC32C3X8(buffer, ITR) \ #define CRC32C3X8(buffer, ITR) \
crc1 = __crc32cd(crc1, *((const uint64_t *)buffer + 42*1 + (ITR)));\ crc1 = __crc32cd(crc1, *((const uint64_t *)buffer + 42*1 + (ITR)));\
crc2 = __crc32cd(crc2, *((const uint64_t *)buffer + 42*2 + (ITR)));\ crc2 = __crc32cd(crc2, *((const uint64_t *)buffer + 42*2 + (ITR)));\
...@@ -119,7 +130,7 @@ uint32_t crc32c_aarch64(uint32_t crc, const unsigned char *buffer, uint64_t len) ...@@ -119,7 +130,7 @@ uint32_t crc32c_aarch64(uint32_t crc, const unsigned char *buffer, uint64_t len)
uint32_t crc0, crc1, crc2; uint32_t crc0, crc1, crc2;
int64_t length= (int64_t)len; int64_t length= (int64_t)len;
crc= 0xFFFFFFFFU; crc^= 0xffffffff;
/* Pmull runtime check here. /* Pmull runtime check here.
* Raspberry Pi 4 supports crc32 but doesn't support pmull (MDEV-23030). * Raspberry Pi 4 supports crc32 but doesn't support pmull (MDEV-23030).
...@@ -282,16 +293,16 @@ unsigned int crc32_aarch64(unsigned int crc, const void *buf, size_t len) ...@@ -282,16 +293,16 @@ unsigned int crc32_aarch64(unsigned int crc, const void *buf, size_t len)
/* if start pointer is not 8 bytes aligned */ /* if start pointer is not 8 bytes aligned */
while ((buf1 != (const uint8_t *) buf8) && len) while ((buf1 != (const uint8_t *) buf8) && len)
{ {
crc= __crc32b(crc, *buf1++); CRC32B(crc, *buf1++);
len--; len--;
} }
for (; len >= 8; len-= 8) for (; len >= 8; len-= 8)
crc= __crc32d(crc, *buf8++); CRC32X(crc, *buf8++);
buf1= (const uint8_t *) buf8; buf1= (const uint8_t *) buf8;
while (len--) while (len--)
crc= __crc32b(crc, *buf1++); CRC32B(crc, *buf1++);
return ~crc; return ~crc;
} }
This diff is collapsed.
This diff is collapsed.
#define CRC32_FUNCTION crc32c_ppc
#define CRC_TABLE
#define POWER8_INTRINSICS
#include "pcc_crc32c_constants.h"
#include "crc_ppc64.h"
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
// Copyright (c) 2017 International Business Machines Corp.
// All rights reserved.
// This source code is licensed under both the GPLv2 (found in the
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t crc32c_ppc(uint32_t crc, unsigned char const *buffer,
unsigned len);
#ifdef __cplusplus
}
#endif
This diff is collapsed.
...@@ -18,40 +18,46 @@ ...@@ -18,40 +18,46 @@
#include <my_sys.h> #include <my_sys.h>
#include <zlib.h> #include <zlib.h>
#if !defined(HAVE_CRC32_VPMSUM)
/* TODO: remove this once zlib adds inherent support for hardware accelerated /* TODO: remove this once zlib adds inherent support for hardware accelerated
crc32 for all architectures. */ crc32 for all architectures. */
static unsigned int my_crc32_zlib(unsigned int crc, const void *data, static unsigned int my_crc32_zlib(unsigned int crc, const void *data,
size_t len) size_t len)
{ {
return (unsigned int) crc32(crc, data, (unsigned int) len); return (unsigned int) crc32(crc, (const Bytef *)data, (unsigned int) len);
} }
my_crc32_t my_checksum= my_crc32_zlib; #ifdef HAVE_PCLMUL
extern "C" int crc32_pclmul_enabled();
extern "C" unsigned int crc32_pclmul(unsigned int, const void *, size_t);
#elif defined(__GNUC__) && defined(HAVE_ARMV8_CRC)
extern "C" int crc32_aarch64_available();
extern "C" unsigned int crc32_aarch64(unsigned int, const void *, size_t);
#endif #endif
#ifdef HAVE_CLMUL_INSTRUCTION
extern int crc32_pclmul_enabled();
extern unsigned int crc32_pclmul(unsigned int, const void *, size_t);
/*----------------------------- x86_64 ---------------------------------*/ typedef unsigned int (*my_crc32_t)(unsigned int, const void *, size_t);
void my_checksum_init(void)
static my_crc32_t init_crc32()
{ {
my_crc32_t func= my_crc32_zlib;
#ifdef HAVE_PCLMUL
if (crc32_pclmul_enabled()) if (crc32_pclmul_enabled())
my_checksum= crc32_pclmul; func = crc32_pclmul;
}
#elif defined(__GNUC__) && defined(HAVE_ARMV8_CRC) #elif defined(__GNUC__) && defined(HAVE_ARMV8_CRC)
/*----------------------------- aarch64 --------------------------------*/ if (crc32_aarch64_available())
func= crc32_aarch64;
#endif
return func;
}
extern unsigned int crc32_aarch64(unsigned int, const void *, size_t); static const my_crc32_t my_checksum_func= init_crc32();
/* Ideally all ARM 64 bit processor should support crc32 but if some model #ifndef __powerpc64__
doesn't support better to find it out through auxillary vector. */ /* For powerpc, my_checksum is defined elsewhere.*/
void my_checksum_init(void) extern "C" unsigned int my_checksum(unsigned int crc, const void *data, size_t len)
{ {
if (crc32_aarch64_available()) return my_checksum_func(crc, data, len);
my_checksum= crc32_aarch64;
} }
#else
void my_checksum_init(void) {}
#endif #endif
...@@ -100,9 +100,6 @@ my_bool my_init(void) ...@@ -100,9 +100,6 @@ my_bool my_init(void)
/* Initialize our mutex handling */ /* Initialize our mutex handling */
my_mutex_init(); my_mutex_init();
/* Initialize CPU architecture specific hardware based crc32 optimization */
my_checksum_init();
if (my_thread_global_init()) if (my_thread_global_init())
return 1; return 1;
......
...@@ -264,7 +264,6 @@ SET(INNOBASE_SOURCES ...@@ -264,7 +264,6 @@ SET(INNOBASE_SOURCES
include/ut0byte.h include/ut0byte.h
include/ut0byte.ic include/ut0byte.ic
include/ut0counter.h include/ut0counter.h
include/ut0crc32.h
include/ut0dbg.h include/ut0dbg.h
include/ut0list.h include/ut0list.h
include/ut0list.ic include/ut0list.ic
...@@ -340,7 +339,6 @@ SET(INNOBASE_SOURCES ...@@ -340,7 +339,6 @@ SET(INNOBASE_SOURCES
trx/trx0sys.cc trx/trx0sys.cc
trx/trx0trx.cc trx/trx0trx.cc
trx/trx0undo.cc trx/trx0undo.cc
ut/ut0crc32.cc
ut/ut0dbg.cc ut/ut0dbg.cc
ut/ut0list.cc ut/ut0list.cc
ut/ut0mem.cc ut/ut0mem.cc
......
...@@ -28,33 +28,10 @@ Created Aug 10, 2011 Vasil Dimov ...@@ -28,33 +28,10 @@ Created Aug 10, 2011 Vasil Dimov
#define ut0crc32_h #define ut0crc32_h
#include "univ.i" #include "univ.i"
#include <my_sys.h>
/********************************************************************//**
Initializes the data structures used by ut_crc32*(). Does not do any
allocations, would not hurt if called twice, but would be pointless. */
void ut_crc32_init();
/** Append data to a CRC-32C checksum.
@param crc current checksum
@param s data to append to the checksum
@param size data length in bytes
@return CRC-32C, using the GF(2) primitive polynomial 0x11EDC6F41,
or 0x1EDC6F41 without the highest degree term */
typedef uint32_t (*ut_crc32_func_t)(uint32_t crc, const byte *s, size_t size);
/** Pointer to CRC32 calculation function. */
extern ut_crc32_func_t ut_crc32_low;
/** Text description of CRC32 implementation */
extern const char* ut_crc32_implementation;
/** Compute CRC-32C over a string of bytes.
@param s data
@param len data length in bytes
@return the CRC-32C of the data */
static inline uint32_t ut_crc32(const byte *s, size_t size) static inline uint32_t ut_crc32(const byte *s, size_t size)
{ {
return ut_crc32_low(0, s, size); return my_crc32c(0, s, size);
} }
#endif /* ut0crc32_h */ #endif /* ut0crc32_h */
...@@ -209,16 +209,6 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "SunPro" ...@@ -209,16 +209,6 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "SunPro"
PROPERTIES COMPILE_FLAGS -xO3) PROPERTIES COMPILE_FLAGS -xO3)
ENDIF() ENDIF()
# Avoid generating Hardware Capabilities due to crc32 instructions
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND CMAKE_SYSTEM_PROCESSOR MATCHES "i386")
MY_CHECK_CXX_COMPILER_FLAG("-Wa,-nH")
IF(have_CXX__Wa__nH)
ADD_COMPILE_FLAGS(
ut/ut0crc32.cc
COMPILE_FLAGS "-Wa,-nH"
)
ENDIF()
ENDIF()
IF(MSVC) IF(MSVC)
# Avoid "unreferenced label" warning in generated file # Avoid "unreferenced label" warning in generated file
......
...@@ -762,7 +762,6 @@ static void srv_init() ...@@ -762,7 +762,6 @@ static void srv_init()
/* Initialize some INFORMATION SCHEMA internal structures */ /* Initialize some INFORMATION SCHEMA internal structures */
trx_i_s_cache_init(trx_i_s_cache); trx_i_s_cache_init(trx_i_s_cache);
ut_crc32_init();
} }
/*********************************************************************//** /*********************************************************************//**
......
...@@ -1223,7 +1223,7 @@ dberr_t srv_start(bool create_new_db) ...@@ -1223,7 +1223,7 @@ dberr_t srv_start(bool create_new_db)
srv_boot(); srv_boot();
ib::info() << ut_crc32_implementation; ib::info() << my_crc32c_implementation();
if (!srv_read_only_mode) { if (!srv_read_only_mode) {
......
This diff is collapsed.
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
MY_ADD_TESTS(bitmap base64 my_atomic my_rdtsc lf my_malloc my_getopt dynstring MY_ADD_TESTS(bitmap base64 my_atomic my_rdtsc lf my_malloc my_getopt dynstring
byte_order byte_order
queues stacktrace LINK_LIBRARIES mysys) queues stacktrace crc32 LINK_LIBRARIES mysys)
MY_ADD_TESTS(my_vsnprintf LINK_LIBRARIES strings mysys) MY_ADD_TESTS(my_vsnprintf LINK_LIBRARIES strings mysys)
MY_ADD_TESTS(aes LINK_LIBRARIES mysys mysys_ssl) MY_ADD_TESTS(aes LINK_LIBRARIES mysys mysys_ssl)
ADD_DEFINITIONS(${SSL_DEFINES}) ADD_DEFINITIONS(${SSL_DEFINES})
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
MY_ADD_TESTS(ma_dyncol LINK_LIBRARIES mysys) MY_ADD_TESTS(ma_dyncol LINK_LIBRARIES mysys)
IF(WIN32) IF(WIN32)
......
/* Copyright (c) MariaDB 2020
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
#include <my_global.h>
#include <my_sys.h>
#include <my_crypt.h>
#include <tap.h>
#include <string.h>
#include <ctype.h>
#include <zlib.h>
/*
Check that optimized crc32 (ieee, or ethernet polynomical) returns the same
result as zlib (not so well optimized, yet, but trustworthy)
*/
#define DO_TEST_CRC32(crc,str) \
ok(crc32(crc,(const Bytef *)str,(uint)(sizeof(str)-1)) == my_checksum(crc, str, sizeof(str)-1), "crc32 '%s'",str)
/* Check that CRC32-C calculation returns correct result*/
#define DO_TEST_CRC32C(crc,str,expected) \
do { \
unsigned int v = my_crc32c(crc, str, sizeof(str)-1); \
printf("crc32(%u,'%s',%zu)=%u\n",crc,str,sizeof(str)-1,v); \
ok(expected == my_crc32c(crc, str, sizeof(str)-1),"crc32c '%s'",str); \
}while(0)
#define LONG_STR "1234567890234568900212345678901231213123321212123123123123123"\
"............................................................................." \
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
"yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" \
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
int main(int argc __attribute__((unused)),char *argv[])
{
MY_INIT(argv[0]);
plan(14);
printf("%s\n",my_crc32c_implementation());
DO_TEST_CRC32(0,"");
DO_TEST_CRC32(1,"");
DO_TEST_CRC32(0,"12345");
DO_TEST_CRC32(1,"12345");
DO_TEST_CRC32(0,"1234567890123456789");
DO_TEST_CRC32(0, LONG_STR);
ok(0 == my_checksum(0, NULL, 0) , "crc32 data = NULL, length = 0");
DO_TEST_CRC32C(0,"", 0);
DO_TEST_CRC32C(1,"", 1);
DO_TEST_CRC32C(0, "12345", 416359221);
DO_TEST_CRC32C(1, "12345", 549473433);
DO_TEST_CRC32C(0, "1234567890123456789", 2366987449);
DO_TEST_CRC32C(0, LONG_STR, 3009234172);
ok(0 == my_crc32c(0, NULL, 0), "crc32c data = NULL, length = 0");
my_end(0);
return exit_status();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment