From 965a3c39718e560c30bf6de81ad9a83cb17ff26d Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Mon, 21 Mar 2016 16:28:25 +1100 Subject: [PATCH 01/12] Move innodb crc32 implementation to mysys During the move use system type definations rather than innobase ones. --- extra/CMakeLists.txt | 14 - include/ut0crc32.h | 64 ++++ mysys/CMakeLists.txt | 15 +- mysys/ut0crc32.cc | 735 +++++++++++++++++++++++++++++++++++ storage/innobase/CMakeLists.txt | 13 - storage/innobase/include/ut0crc32.h | 60 --- storage/innobase/ut/ut0crc32.cc | 736 ------------------------------------ 7 files changed, 813 insertions(+), 824 deletions(-) create mode 100644 include/ut0crc32.h create mode 100644 mysys/ut0crc32.cc delete mode 100644 storage/innobase/include/ut0crc32.h delete mode 100644 storage/innobase/ut/ut0crc32.cc diff --git a/extra/CMakeLists.txt b/extra/CMakeLists.txt index 3adf988..344e387 100644 --- a/extra/CMakeLists.txt +++ b/extra/CMakeLists.txt @@ -118,26 +118,12 @@ IF(WITH_INNOBASE_STORAGE_ENGINE) ADD_DEFINITIONS("-DUNIV_INNOCHECKSUM") SET(INNOBASE_SOURCES ../storage/innobase/buf/buf0checksum.cc - ../storage/innobase/ut/ut0crc32.cc ../storage/innobase/ut/ut0ut.cc ../storage/innobase/buf/buf0buf.cc ../storage/innobase/page/page0zip.cc ../storage/innobase/os/os0file.cc ) - # Avoid generating Hardware Capabilities due to crc32 instructions - IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND - CMAKE_SYSTEM_PROCESSOR MATCHES "i386") - INCLUDE(${MYSQL_CMAKE_SCRIPT_DIR}/compile_flags.cmake) - MY_CHECK_CXX_COMPILER_FLAG("-Wa,-nH" HAVE_WA_NH) - IF(HAVE_WA_NH) - ADD_COMPILE_FLAGS( - ../storage/innobase/ut/ut0crc32.cc - COMPILE_FLAGS "-Wa,-nH" - ) - ENDIF() - ENDIF() - MYSQL_ADD_EXECUTABLE(innochecksum innochecksum.cc ${INNOBASE_SOURCES}) TARGET_LINK_LIBRARIES(innochecksum mysys mysys_ssl ${LZ4_LIBRARY}) ADD_DEPENDENCIES(innochecksum GenError) diff --git a/include/ut0crc32.h b/include/ut0crc32.h new file mode 100644 index 0000000..7fa3a99 --- /dev/null +++ b/include/ut0crc32.h @@ -0,0 +1,64 @@ +/***************************************************************************** + +Copyright (c) 2011, 2015, Oracle and/or its affiliates. All Rights Reserved. + +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 Street, Suite 500, Boston, MA 02110-1335 USA + +*****************************************************************************/ + +/**************************************************//** +@file include/ut0crc32.h +CRC32 implementation + +Created Aug 10, 2011 Vasil Dimov +*******************************************************/ + +#ifndef ut0crc32_h +#define ut0crc32_h + +#include + +/********************************************************************//** +Initializes the data structures used by ut_crc32*(). Does not do any +allocations, would not hurt if called twice, but would be pointless. */ +/* from UNIV_INTERN in storage/innobase/include/univ.i */ +#if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(sun) || defined(__INTEL_COMPILER) +__attribute__((visibility ("hidden"))) +#endif +void +ut_crc32_init(); +/*===========*/ + +/********************************************************************//** +Calculates CRC32. +@param ptr - data over which to calculate CRC32. +@param len - data length in bytes. +@return CRC32 (CRC-32C, using the GF(2) primitive polynomial 0x11EDC6F41, +or 0x1EDC6F41 without the high-order bit) */ +typedef uint32_t (*ut_crc32_func_t)(const uint8* ptr, my_ulonglong len); + +/** Pointer to CRC32 calculation function. */ +extern ut_crc32_func_t ut_crc32; + +/** Pointer to CRC32 calculation function, which uses big-endian byte order +when converting byte strings to integers internally. */ +extern ut_crc32_func_t ut_crc32_legacy_big_endian; + +/** Pointer to CRC32-byte-by-byte calculation function (byte order agnostic, +but very slow). */ +extern ut_crc32_func_t ut_crc32_byte_by_byte; + +/** Flag that tells whether the CPU supports CRC32 or not */ +extern my_bool ut_crc32_sse2_enabled; + +#endif /* ut0crc32_h */ diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt index 35815e8..bb325ca 100644 --- a/mysys/CMakeLists.txt +++ b/mysys/CMakeLists.txt @@ -34,7 +34,7 @@ SET(MYSYS_SOURCES array.c charset-def.c charset.c checksum.c thr_rwlock.c tree.c typelib.c base64.c my_memmem.c lf_alloc-pin.c lf_dynarray.c lf_hash.c my_rdtsc.c psi_noop.c my_syslog.c - my_chmod.c my_thread.c) + my_chmod.c my_thread.c ut0crc32.cc) IF (WIN32) LIST(APPEND MYSYS_SOURCES @@ -60,6 +60,19 @@ IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND CMAKE_C_COMPILER_ID MATCHES "SunPro") PROPERTIES COMPILE_FLAGS "${CMAKE_CURRENT_SOURCE_DIR}/my_timer_cycles.il") ENDIF() +# Avoid generating Hardware Capabilities due to crc32 instructions +IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND + CMAKE_SYSTEM_PROCESSOR MATCHES "i386") + INCLUDE(${MYSQL_CMAKE_SCRIPT_DIR}/compile_flags.cmake) + MY_CHECK_CXX_COMPILER_FLAG("-Wa,-nH" HAVE_WA_NH) + IF(HAVE_WA_NH) + ADD_COMPILE_FLAGS( + ut0crc32.cc + COMPILE_FLAGS "-Wa,-nH" + ) + ENDIF() +ENDIF() + IF(HAVE_LINUX_LARGE_PAGES) SET(MYSYS_SOURCES ${MYSYS_SOURCES} my_largepage.c) ENDIF() diff --git a/mysys/ut0crc32.cc b/mysys/ut0crc32.cc new file mode 100644 index 0000000..fb93ea7 --- /dev/null +++ b/mysys/ut0crc32.cc @@ -0,0 +1,735 @@ +/***************************************************************************** + +Copyright (c) 2009, 2010 Facebook, Inc. All Rights Reserved. +Copyright (c) 2011, 2015, Oracle and/or its affiliates. All Rights Reserved. + +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 Street, Suite 500, Boston, MA 02110-1335 USA + +*****************************************************************************/ + +/***************************************************************//** +@file ut/ut0crc32.cc +CRC32 implementation from Facebook, based on the zlib implementation. + +Created Aug 8, 2011, Vasil Dimov, based on mysys/my_crc32.c and +mysys/my_perf.c, contributed by Facebook under the following license. +********************************************************************/ + +/* Copyright (C) 2009-2010 Facebook, Inc. All Rights Reserved. + + Dual licensed under BSD license and GPLv2. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY FACEBOOK, INC. ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + EVENT SHALL FACEBOOK, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + 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 Street, Suite 500, Boston, MA 02110-1335 USA */ + +/* The below CRC32 implementation is based on the implementation included with + * zlib with modifications to process 8 bytes at a time and using SSE 4.2 + * extensions when available. The polynomial constant has been changed to + * match the one used by SSE 4.2 and does not return the same value as the + * version used by zlib. The original zlib copyright notice follows. */ + +/* crc32.c -- compute the CRC-32 of a buf stream + * Copyright (C) 1995-2005 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + * + * Thanks to Rodney Brown for his contribution of faster + * CRC methods: exclusive-oring 32 bits of buf at a time, and pre-computing + * tables for updating the shift register in one step with three exclusive-ors + * instead of four steps with four exclusive-ors. This results in about a + * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. + */ + +// First include (the generated) my_config.h, to get correct platform defines. +#include "my_config.h" +#include + +#include "ut0crc32.h" + +/** Pointer to CRC32 calculation function. */ +ut_crc32_func_t ut_crc32; + +/** Pointer to CRC32 calculation function, which uses big-endian byte order +when converting byte strings to integers internally. */ +ut_crc32_func_t ut_crc32_legacy_big_endian; + +/** Pointer to CRC32-byte-by-byte calculation function (byte order agnostic, +but very slow). */ +ut_crc32_func_t ut_crc32_byte_by_byte; + +/** Swap the byte order of an 8 byte integer. +@param[in] i 8-byte integer +@return 8-byte integer */ +inline +uint64 +ut_crc32_swap_byteorder( + uint64 i) +{ + return(i << 56 + | (i & 0x000000000000FF00ULL) << 40 + | (i & 0x0000000000FF0000ULL) << 24 + | (i & 0x00000000FF000000ULL) << 8 + | (i & 0x000000FF00000000ULL) >> 8 + | (i & 0x0000FF0000000000ULL) >> 24 + | (i & 0x00FF000000000000ULL) >> 40 + | i >> 56); +} + +/* CRC32 hardware implementation. */ + +/* Flag that tells whether the CPU supports CRC32 or not */ +my_bool ut_crc32_sse2_enabled = false; + +#if defined(__GNUC__) && defined(__x86_64__) +/********************************************************************//** +Fetches CPU info */ +static +void +ut_cpuid( +/*=====*/ + uint32 vend[3], /*!< out: CPU vendor */ + uint32* model, /*!< out: CPU model */ + uint32* family, /*!< out: CPU family */ + uint32* stepping, /*!< out: CPU stepping */ + uint32* features_ecx, /*!< out: CPU features ecx */ + uint32* features_edx) /*!< out: CPU features edx */ +{ + uint32 sig; + asm("cpuid" : "=b" (vend[0]), "=c" (vend[2]), "=d" (vend[1]) : "a" (0)); + asm("cpuid" : "=a" (sig), "=c" (*features_ecx), "=d" (*features_edx) + : "a" (1) + : "ebx"); + + *model = ((sig >> 4) & 0xF); + *family = ((sig >> 8) & 0xF); + *stepping = (sig & 0xF); + + if (memcmp(vend, "GenuineIntel", 12) == 0 + || (memcmp(vend, "AuthenticAMD", 12) == 0 && *family == 0xF)) { + + *model += (((sig >> 16) & 0xF) << 4); + *family += ((sig >> 20) & 0xFF); + } +} + +/** Calculate CRC32 over 8-bit data using a hardware/CPU instruction. +@param[in,out] crc crc32 checksum so far when this function is called, +when the function ends it will contain the new checksum +@param[in,out] data data to be checksummed, the pointer will be advanced +with 1 byte +@param[in,out] len remaining bytes, it will be decremented with 1 */ +inline +void +ut_crc32_8_hw( + uint32* crc, + const uint8** data, + my_ulonglong* len) +{ + asm("crc32b %1, %0" + /* output operands */ + : "+r" (*crc) + /* input operands */ + : "rm" ((*data)[0])); + + (*data)++; + (*len)--; +} + +/** Calculate CRC32 over a 64-bit integer using a hardware/CPU instruction. +@param[in] crc crc32 checksum so far +@param[in] data data to be checksummed +@return resulting checksum of crc + crc(data) */ +inline +uint32 +ut_crc32_64_low_hw( + uint32 crc, + uint64 data) +{ + uint64 crc_64bit = crc; + + asm("crc32q %1, %0" + /* output operands */ + : "+r" (crc_64bit) + /* input operands */ + : "rm" (data)); + + return(static_cast(crc_64bit)); +} + +/** Calculate CRC32 over 64-bit byte string using a hardware/CPU instruction. +@param[in,out] crc crc32 checksum so far when this function is called, +when the function ends it will contain the new checksum +@param[in,out] data data to be checksummed, the pointer will be advanced +with 8 bytes +@param[in,out] len remaining bytes, it will be decremented with 8 */ +inline +void +ut_crc32_64_hw( + uint32* crc, + const uint8** data, + my_ulonglong* len) +{ + uint64 data_int = *reinterpret_cast(*data); + +#ifdef WORDS_BIGENDIAN + /* Currently we only support x86_64 (little endian) CPUs. In case + some big endian CPU supports a CRC32 instruction, then maybe we will + need a byte order swap here. */ +#error Dont know how to handle big endian CPUs + /* + data_int = ut_crc32_swap_byteorder(data_int); + */ +#endif /* WORDS_BIGENDIAN */ + + *crc = ut_crc32_64_low_hw(*crc, data_int); + + *data += 8; + *len -= 8; +} + +/** Calculate CRC32 over 64-bit byte string using a hardware/CPU instruction. +The byte string is converted to a 64-bit integer using big endian byte order. +@param[in,out] crc crc32 checksum so far when this function is called, +when the function ends it will contain the new checksum +@param[in,out] data data to be checksummed, the pointer will be advanced +with 8 bytes +@param[in,out] len remaining bytes, it will be decremented with 8 */ +inline +void +ut_crc32_64_legacy_big_endian_hw( + uint32* crc, + const uint8** data, + my_ulonglong* len) +{ + uint64 data_int = *reinterpret_cast(*data); + +#ifndef WORDS_BIGENDIAN + data_int = ut_crc32_swap_byteorder(data_int); +#else + /* Currently we only support x86_64 (little endian) CPUs. In case + some big endian CPU supports a CRC32 instruction, then maybe we will + NOT need a byte order swap here. */ +#error Dont know how to handle big endian CPUs +#endif /* WORDS_BIGENDIAN */ + + *crc = ut_crc32_64_low_hw(*crc, data_int); + + *data += 8; + *len -= 8; +} + +/** Calculates CRC32 using hardware/CPU instructions. +@param[in] buf data over which to calculate CRC32 +@param[in] len data length +@return CRC-32C (polynomial 0x11EDC6F41) */ +uint32 +ut_crc32_hw( + const uint8* buf, + my_ulonglong len) +{ + uint32 crc = 0xFFFFFFFFU; + + DBUG_ASSERT(ut_crc32_sse2_enabled); + + /* Calculate byte-by-byte up to an 8-byte aligned address. After + this consume the input 8-bytes at a time. */ + while (len > 0 && (reinterpret_cast(buf) & 7) != 0) { + ut_crc32_8_hw(&crc, &buf, &len); + } + + /* Perf testing + ./unittest/gunit/innodb/merge_innodb_tests-t --gtest_filter=ut0crc32.perf + on CPU "Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz" + with different N in "while (len >= N) {" shows: + N=16 + 2.867254 sec + 2.866860 sec + 2.867973 sec + + N=32 + 2.715725 sec + 2.713008 sec + 2.712520 sec + (5.36% speedup over N=16) + + N=64 + 2.634140 sec + 2.636558 sec + 2.636488 sec + (2.88% speedup over N=32) + + N=128 + 2.599534 sec + 2.599919 sec + 2.598035 sec + (1.39% speedup over N=64) + + N=256 + 2.576993 sec + 2.576748 sec + 2.575700 sec + (0.87% speedup over N=128) + + N=512 + 2.693928 sec + 2.691663 sec + 2.692142 sec + (4.51% slowdown over N=256) + */ + while (len >= 128) { + /* This call is repeated 16 times. 16 * 8 = 128. */ + ut_crc32_64_hw(&crc, &buf, &len); + ut_crc32_64_hw(&crc, &buf, &len); + ut_crc32_64_hw(&crc, &buf, &len); + ut_crc32_64_hw(&crc, &buf, &len); + ut_crc32_64_hw(&crc, &buf, &len); + ut_crc32_64_hw(&crc, &buf, &len); + ut_crc32_64_hw(&crc, &buf, &len); + ut_crc32_64_hw(&crc, &buf, &len); + ut_crc32_64_hw(&crc, &buf, &len); + ut_crc32_64_hw(&crc, &buf, &len); + ut_crc32_64_hw(&crc, &buf, &len); + ut_crc32_64_hw(&crc, &buf, &len); + ut_crc32_64_hw(&crc, &buf, &len); + ut_crc32_64_hw(&crc, &buf, &len); + ut_crc32_64_hw(&crc, &buf, &len); + ut_crc32_64_hw(&crc, &buf, &len); + } + + while (len >= 8) { + ut_crc32_64_hw(&crc, &buf, &len); + } + + while (len > 0) { + ut_crc32_8_hw(&crc, &buf, &len); + } + + return(~crc); +} + +/** Calculates CRC32 using hardware/CPU instructions. +This function uses big endian byte ordering when converting byte sequence to +integers. +@param[in] buf data over which to calculate CRC32 +@param[in] len data length +@return CRC-32C (polynomial 0x11EDC6F41) */ +uint32 +ut_crc32_legacy_big_endian_hw( + const uint8* buf, + my_ulonglong len) +{ + uint32 crc = 0xFFFFFFFFU; + + DBUG_ASSERT(ut_crc32_sse2_enabled); + + /* Calculate byte-by-byte up to an 8-byte aligned address. After + this consume the input 8-bytes at a time. */ + while (len > 0 && (reinterpret_cast(buf) & 7) != 0) { + ut_crc32_8_hw(&crc, &buf, &len); + } + + while (len >= 128) { + /* This call is repeated 16 times. 16 * 8 = 128. */ + ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + } + + while (len >= 8) { + ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + } + + while (len > 0) { + ut_crc32_8_hw(&crc, &buf, &len); + } + + return(~crc); +} + +/** Calculates CRC32 using hardware/CPU instructions. +This function processes one byte at a time (very slow) and thus it does +not depend on the byte order of the machine. +@param[in] buf data over which to calculate CRC32 +@param[in] len data length +@return CRC-32C (polynomial 0x11EDC6F41) */ +uint32 +ut_crc32_byte_by_byte_hw( + const uint8* buf, + my_ulonglong len) +{ + uint32 crc = 0xFFFFFFFFU; + + DBUG_ASSERT(ut_crc32_sse2_enabled); + + while (len > 0) { + ut_crc32_8_hw(&crc, &buf, &len); + } + + return(~crc); +} +#endif /* defined(__GNUC__) && defined(__x86_64__) */ + +/* CRC32 software implementation. */ + +/* Precalculated table used to generate the CRC32 if the CPU does not +have support for it */ +static uint32 ut_crc32_slice8_table[8][256]; +static bool ut_crc32_slice8_table_initialized = false; + +/********************************************************************//** +Initializes the table that is used to generate the CRC32 if the CPU does +not have support for it. */ +static +void +ut_crc32_slice8_table_init() +/*========================*/ +{ + /* bit-reversed poly 0x1EDC6F41 (from SSE42 crc32 instruction) */ + static const uint32 poly = 0x82f63b78; + uint32 n; + uint32 k; + uint32 c; + + for (n = 0; n < 256; n++) { + c = n; + for (k = 0; k < 8; k++) { + c = (c & 1) ? (poly ^ (c >> 1)) : (c >> 1); + } + ut_crc32_slice8_table[0][n] = c; + } + + for (n = 0; n < 256; n++) { + c = ut_crc32_slice8_table[0][n]; + for (k = 1; k < 8; k++) { + c = ut_crc32_slice8_table[0][c & 0xFF] ^ (c >> 8); + ut_crc32_slice8_table[k][n] = c; + } + } + + ut_crc32_slice8_table_initialized = true; +} + +/** Calculate CRC32 over 8-bit data using a software implementation. +@param[in,out] crc crc32 checksum so far when this function is called, +when the function ends it will contain the new checksum +@param[in,out] data data to be checksummed, the pointer will be advanced +with 1 byte +@param[in,out] len remaining bytes, it will be decremented with 1 */ +inline +void +ut_crc32_8_sw( + uint32* crc, + const uint8** data, + my_ulonglong* len) +{ + const uint8_t i = (*crc ^ (*data)[0]) & 0xFF; + + *crc = (*crc >> 8) ^ ut_crc32_slice8_table[0][i]; + + (*data)++; + (*len)--; +} + +/** Calculate CRC32 over a 64-bit integer using a software implementation. +@param[in] crc crc32 checksum so far +@param[in] data data to be checksummed +@return resulting checksum of crc + crc(data) */ +inline +uint32 +ut_crc32_64_low_sw( + uint32 crc, + uint64 data) +{ + const uint64 i = crc ^ data; + + return( + ut_crc32_slice8_table[7][(i ) & 0xFF] ^ + ut_crc32_slice8_table[6][(i >> 8) & 0xFF] ^ + ut_crc32_slice8_table[5][(i >> 16) & 0xFF] ^ + ut_crc32_slice8_table[4][(i >> 24) & 0xFF] ^ + ut_crc32_slice8_table[3][(i >> 32) & 0xFF] ^ + ut_crc32_slice8_table[2][(i >> 40) & 0xFF] ^ + ut_crc32_slice8_table[1][(i >> 48) & 0xFF] ^ + ut_crc32_slice8_table[0][(i >> 56)] + ); +} + +/** Calculate CRC32 over 64-bit byte string using a software implementation. +@param[in,out] crc crc32 checksum so far when this function is called, +when the function ends it will contain the new checksum +@param[in,out] data data to be checksummed, the pointer will be advanced +with 8 bytes +@param[in,out] len remaining bytes, it will be decremented with 8 */ +inline +void +ut_crc32_64_sw( + uint32* crc, + const uint8** data, + my_ulonglong* len) +{ + uint64 data_int = *reinterpret_cast(*data); + +#ifdef WORDS_BIGENDIAN + data_int = ut_crc32_swap_byteorder(data_int); +#endif /* WORDS_BIGENDIAN */ + + *crc = ut_crc32_64_low_sw(*crc, data_int); + + *data += 8; + *len -= 8; +} + +/** Calculate CRC32 over 64-bit byte string using a software implementation. +The byte string is converted to a 64-bit integer using big endian byte order. +@param[in,out] crc crc32 checksum so far when this function is called, +when the function ends it will contain the new checksum +@param[in,out] data data to be checksummed, the pointer will be advanced +with 8 bytes +@param[in,out] len remaining bytes, it will be decremented with 8 */ +inline +void +ut_crc32_64_legacy_big_endian_sw( + uint32* crc, + const uint8** data, + my_ulonglong* len) +{ + uint64 data_int = *reinterpret_cast(*data); + +#ifndef WORDS_BIGENDIAN + data_int = ut_crc32_swap_byteorder(data_int); +#endif /* WORDS_BIGENDIAN */ + + *crc = ut_crc32_64_low_sw(*crc, data_int); + + *data += 8; + *len -= 8; +} + +/** Calculates CRC32 in software, without using CPU instructions. +@param[in] buf data over which to calculate CRC32 +@param[in] len data length +@return CRC-32C (polynomial 0x11EDC6F41) */ +uint32 +ut_crc32_sw( + const uint8* buf, + my_ulonglong len) +{ + uint32 crc = 0xFFFFFFFFU; + + DBUG_ASSERT(ut_crc32_slice8_table_initialized); + + /* Calculate byte-by-byte up to an 8-byte aligned address. After + this consume the input 8-bytes at a time. */ + while (len > 0 && (reinterpret_cast(buf) & 7) != 0) { + ut_crc32_8_sw(&crc, &buf, &len); + } + + while (len >= 128) { + /* This call is repeated 16 times. 16 * 8 = 128. */ + ut_crc32_64_sw(&crc, &buf, &len); + ut_crc32_64_sw(&crc, &buf, &len); + ut_crc32_64_sw(&crc, &buf, &len); + ut_crc32_64_sw(&crc, &buf, &len); + ut_crc32_64_sw(&crc, &buf, &len); + ut_crc32_64_sw(&crc, &buf, &len); + ut_crc32_64_sw(&crc, &buf, &len); + ut_crc32_64_sw(&crc, &buf, &len); + ut_crc32_64_sw(&crc, &buf, &len); + ut_crc32_64_sw(&crc, &buf, &len); + ut_crc32_64_sw(&crc, &buf, &len); + ut_crc32_64_sw(&crc, &buf, &len); + ut_crc32_64_sw(&crc, &buf, &len); + ut_crc32_64_sw(&crc, &buf, &len); + ut_crc32_64_sw(&crc, &buf, &len); + ut_crc32_64_sw(&crc, &buf, &len); + } + + while (len >= 8) { + ut_crc32_64_sw(&crc, &buf, &len); + } + + while (len > 0) { + ut_crc32_8_sw(&crc, &buf, &len); + } + + return(~crc); +} + +/** Calculates CRC32 in software, without using CPU instructions. +This function uses big endian byte ordering when converting byte sequence to +integers. +@param[in] buf data over which to calculate CRC32 +@param[in] len data length +@return CRC-32C (polynomial 0x11EDC6F41) */ +uint32 +ut_crc32_legacy_big_endian_sw( + const uint8* buf, + my_ulonglong len) +{ + uint32 crc = 0xFFFFFFFFU; + + DBUG_ASSERT(ut_crc32_slice8_table_initialized); + + /* Calculate byte-by-byte up to an 8-byte aligned address. After + this consume the input 8-bytes at a time. */ + while (len > 0 && (reinterpret_cast(buf) & 7) != 0) { + ut_crc32_8_sw(&crc, &buf, &len); + } + + while (len >= 128) { + /* This call is repeated 16 times. 16 * 8 = 128. */ + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + } + + while (len >= 8) { + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + } + + while (len > 0) { + ut_crc32_8_sw(&crc, &buf, &len); + } + + return(~crc); +} + +/** Calculates CRC32 in software, without using CPU instructions. +This function processes one byte at a time (very slow) and thus it does +not depend on the byte order of the machine. +@param[in] buf data over which to calculate CRC32 +@param[in] len data length +@return CRC-32C (polynomial 0x11EDC6F41) */ +uint32 +ut_crc32_byte_by_byte_sw( + const uint8* buf, + my_ulonglong len) +{ + uint32 crc = 0xFFFFFFFFU; + + DBUG_ASSERT(ut_crc32_slice8_table_initialized); + + while (len > 0) { + ut_crc32_8_sw(&crc, &buf, &len); + } + + return(~crc); +} + +/********************************************************************//** +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() +/*===========*/ +{ +#if defined(__GNUC__) && defined(__x86_64__) + uint32 vend[3]; + uint32 model; + uint32 family; + uint32 stepping; + uint32 features_ecx; + uint32 features_edx; + + ut_cpuid(vend, &model, &family, &stepping, + &features_ecx, &features_edx); + + /* Valgrind does not understand the CRC32 instructions: + + vex amd64->IR: unhandled instruction bytes: 0xF2 0x48 0xF 0x38 0xF0 0xA + valgrind: Unrecognised instruction at address 0xad3db5. + Your program just tried to execute an instruction that Valgrind + did not recognise. There are two possible reasons for this. + 1. Your program has a bug and erroneously jumped to a non-code + location. If you are running Memcheck and you just saw a + warning about a bad jump, it's probably your program's fault. + 2. The instruction is legitimate but Valgrind doesn't handle it, + i.e. it's Valgrind's fault. If you think this is the case or + you are not sure, please let us know and we'll try to fix it. + Either way, Valgrind will now raise a SIGILL signal which will + probably kill your program. + + */ +#ifndef UNIV_DEBUG_VALGRIND + ut_crc32_sse2_enabled = (features_ecx >> 20) & 1; +#endif /* UNIV_DEBUG_VALGRIND */ + + if (ut_crc32_sse2_enabled) { + ut_crc32 = ut_crc32_hw; + ut_crc32_legacy_big_endian = ut_crc32_legacy_big_endian_hw; + ut_crc32_byte_by_byte = ut_crc32_byte_by_byte_hw; + } + +#endif /* defined(__GNUC__) && defined(__x86_64__) */ + + if (!ut_crc32_sse2_enabled) { + ut_crc32_slice8_table_init(); + ut_crc32 = ut_crc32_sw; + ut_crc32_legacy_big_endian = ut_crc32_legacy_big_endian_sw; + ut_crc32_byte_by_byte = ut_crc32_byte_by_byte_sw; + } +} diff --git a/storage/innobase/CMakeLists.txt b/storage/innobase/CMakeLists.txt index c8bbd0c..02d579b 100644 --- a/storage/innobase/CMakeLists.txt +++ b/storage/innobase/CMakeLists.txt @@ -133,7 +133,6 @@ SET(INNOBASE_SOURCES trx/trx0undo.cc usr/usr0sess.cc ut/ut0byte.cc - ut/ut0crc32.cc ut/ut0dbg.cc ut/ut0list.cc ut/ut0mem.cc @@ -158,18 +157,6 @@ IF(WITH_INNOBASE_STORAGE_ENGINE) ADD_DEPENDENCIES(innobase GenError) ENDIF() -# Avoid generating Hardware Capabilities due to crc32 instructions -IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND CMAKE_SYSTEM_PROCESSOR MATCHES "i386") - INCLUDE(${MYSQL_CMAKE_SCRIPT_DIR}/compile_flags.cmake) - MY_CHECK_CXX_COMPILER_FLAG("-Wa,-nH" HAVE_WA_NH) - IF(HAVE_WA_NH) - ADD_COMPILE_FLAGS( - ut/ut0crc32.cc - COMPILE_FLAGS "-Wa,-nH" - ) - ENDIF() -ENDIF() - # A GCC bug causes crash when compiling these files on ARM64 with -O1+ # Compile them with -O0 as a workaround until the GCC bug is fixed. IF(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") diff --git a/storage/innobase/include/ut0crc32.h b/storage/innobase/include/ut0crc32.h deleted file mode 100644 index 04eb9e0..0000000 --- a/storage/innobase/include/ut0crc32.h +++ /dev/null @@ -1,60 +0,0 @@ -/***************************************************************************** - -Copyright (c) 2011, 2015, Oracle and/or its affiliates. All Rights Reserved. - -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 Street, Suite 500, Boston, MA 02110-1335 USA - -*****************************************************************************/ - -/**************************************************//** -@file include/ut0crc32.h -CRC32 implementation - -Created Aug 10, 2011 Vasil Dimov -*******************************************************/ - -#ifndef ut0crc32_h -#define ut0crc32_h - -#include "univ.i" - -/********************************************************************//** -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(); -/*===========*/ - -/********************************************************************//** -Calculates CRC32. -@param ptr - data over which to calculate CRC32. -@param len - data length in bytes. -@return CRC32 (CRC-32C, using the GF(2) primitive polynomial 0x11EDC6F41, -or 0x1EDC6F41 without the high-order bit) */ -typedef uint32_t (*ut_crc32_func_t)(const byte* ptr, ulint len); - -/** Pointer to CRC32 calculation function. */ -extern ut_crc32_func_t ut_crc32; - -/** Pointer to CRC32 calculation function, which uses big-endian byte order -when converting byte strings to integers internally. */ -extern ut_crc32_func_t ut_crc32_legacy_big_endian; - -/** Pointer to CRC32-byte-by-byte calculation function (byte order agnostic, -but very slow). */ -extern ut_crc32_func_t ut_crc32_byte_by_byte; - -/** Flag that tells whether the CPU supports CRC32 or not */ -extern bool ut_crc32_sse2_enabled; - -#endif /* ut0crc32_h */ diff --git a/storage/innobase/ut/ut0crc32.cc b/storage/innobase/ut/ut0crc32.cc deleted file mode 100644 index 979713f..0000000 --- a/storage/innobase/ut/ut0crc32.cc +++ /dev/null @@ -1,736 +0,0 @@ -/***************************************************************************** - -Copyright (c) 2009, 2010 Facebook, Inc. All Rights Reserved. -Copyright (c) 2011, 2015, Oracle and/or its affiliates. All Rights Reserved. - -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 Street, Suite 500, Boston, MA 02110-1335 USA - -*****************************************************************************/ - -/***************************************************************//** -@file ut/ut0crc32.cc -CRC32 implementation from Facebook, based on the zlib implementation. - -Created Aug 8, 2011, Vasil Dimov, based on mysys/my_crc32.c and -mysys/my_perf.c, contributed by Facebook under the following license. -********************************************************************/ - -/* Copyright (C) 2009-2010 Facebook, Inc. All Rights Reserved. - - Dual licensed under BSD license and GPLv2. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY FACEBOOK, INC. ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - EVENT SHALL FACEBOOK, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - 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 Street, Suite 500, Boston, MA 02110-1335 USA */ - -/* The below CRC32 implementation is based on the implementation included with - * zlib with modifications to process 8 bytes at a time and using SSE 4.2 - * extensions when available. The polynomial constant has been changed to - * match the one used by SSE 4.2 and does not return the same value as the - * version used by zlib. The original zlib copyright notice follows. */ - -/* crc32.c -- compute the CRC-32 of a buf stream - * Copyright (C) 1995-2005 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - * - * Thanks to Rodney Brown for his contribution of faster - * CRC methods: exclusive-oring 32 bits of buf at a time, and pre-computing - * tables for updating the shift register in one step with three exclusive-ors - * instead of four steps with four exclusive-ors. This results in about a - * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. - */ - -// First include (the generated) my_config.h, to get correct platform defines. -#include "my_config.h" -#include - -#include "univ.i" -#include "ut0crc32.h" - -/** Pointer to CRC32 calculation function. */ -ut_crc32_func_t ut_crc32; - -/** Pointer to CRC32 calculation function, which uses big-endian byte order -when converting byte strings to integers internally. */ -ut_crc32_func_t ut_crc32_legacy_big_endian; - -/** Pointer to CRC32-byte-by-byte calculation function (byte order agnostic, -but very slow). */ -ut_crc32_func_t ut_crc32_byte_by_byte; - -/** Swap the byte order of an 8 byte integer. -@param[in] i 8-byte integer -@return 8-byte integer */ -inline -uint64_t -ut_crc32_swap_byteorder( - uint64_t i) -{ - return(i << 56 - | (i & 0x000000000000FF00ULL) << 40 - | (i & 0x0000000000FF0000ULL) << 24 - | (i & 0x00000000FF000000ULL) << 8 - | (i & 0x000000FF00000000ULL) >> 8 - | (i & 0x0000FF0000000000ULL) >> 24 - | (i & 0x00FF000000000000ULL) >> 40 - | i >> 56); -} - -/* CRC32 hardware implementation. */ - -/* Flag that tells whether the CPU supports CRC32 or not */ -bool ut_crc32_sse2_enabled = false; - -#if defined(__GNUC__) && defined(__x86_64__) -/********************************************************************//** -Fetches CPU info */ -static -void -ut_cpuid( -/*=====*/ - uint32_t vend[3], /*!< out: CPU vendor */ - uint32_t* model, /*!< out: CPU model */ - uint32_t* family, /*!< out: CPU family */ - uint32_t* stepping, /*!< out: CPU stepping */ - uint32_t* features_ecx, /*!< out: CPU features ecx */ - uint32_t* features_edx) /*!< out: CPU features edx */ -{ - uint32_t sig; - asm("cpuid" : "=b" (vend[0]), "=c" (vend[2]), "=d" (vend[1]) : "a" (0)); - asm("cpuid" : "=a" (sig), "=c" (*features_ecx), "=d" (*features_edx) - : "a" (1) - : "ebx"); - - *model = ((sig >> 4) & 0xF); - *family = ((sig >> 8) & 0xF); - *stepping = (sig & 0xF); - - if (memcmp(vend, "GenuineIntel", 12) == 0 - || (memcmp(vend, "AuthenticAMD", 12) == 0 && *family == 0xF)) { - - *model += (((sig >> 16) & 0xF) << 4); - *family += ((sig >> 20) & 0xFF); - } -} - -/** Calculate CRC32 over 8-bit data using a hardware/CPU instruction. -@param[in,out] crc crc32 checksum so far when this function is called, -when the function ends it will contain the new checksum -@param[in,out] data data to be checksummed, the pointer will be advanced -with 1 byte -@param[in,out] len remaining bytes, it will be decremented with 1 */ -inline -void -ut_crc32_8_hw( - uint32_t* crc, - const byte** data, - ulint* len) -{ - asm("crc32b %1, %0" - /* output operands */ - : "+r" (*crc) - /* input operands */ - : "rm" ((*data)[0])); - - (*data)++; - (*len)--; -} - -/** Calculate CRC32 over a 64-bit integer using a hardware/CPU instruction. -@param[in] crc crc32 checksum so far -@param[in] data data to be checksummed -@return resulting checksum of crc + crc(data) */ -inline -uint32_t -ut_crc32_64_low_hw( - uint32_t crc, - uint64_t data) -{ - uint64_t crc_64bit = crc; - - asm("crc32q %1, %0" - /* output operands */ - : "+r" (crc_64bit) - /* input operands */ - : "rm" (data)); - - return(static_cast(crc_64bit)); -} - -/** Calculate CRC32 over 64-bit byte string using a hardware/CPU instruction. -@param[in,out] crc crc32 checksum so far when this function is called, -when the function ends it will contain the new checksum -@param[in,out] data data to be checksummed, the pointer will be advanced -with 8 bytes -@param[in,out] len remaining bytes, it will be decremented with 8 */ -inline -void -ut_crc32_64_hw( - uint32_t* crc, - const byte** data, - ulint* len) -{ - uint64_t data_int = *reinterpret_cast(*data); - -#ifdef WORDS_BIGENDIAN - /* Currently we only support x86_64 (little endian) CPUs. In case - some big endian CPU supports a CRC32 instruction, then maybe we will - need a byte order swap here. */ -#error Dont know how to handle big endian CPUs - /* - data_int = ut_crc32_swap_byteorder(data_int); - */ -#endif /* WORDS_BIGENDIAN */ - - *crc = ut_crc32_64_low_hw(*crc, data_int); - - *data += 8; - *len -= 8; -} - -/** Calculate CRC32 over 64-bit byte string using a hardware/CPU instruction. -The byte string is converted to a 64-bit integer using big endian byte order. -@param[in,out] crc crc32 checksum so far when this function is called, -when the function ends it will contain the new checksum -@param[in,out] data data to be checksummed, the pointer will be advanced -with 8 bytes -@param[in,out] len remaining bytes, it will be decremented with 8 */ -inline -void -ut_crc32_64_legacy_big_endian_hw( - uint32_t* crc, - const byte** data, - ulint* len) -{ - uint64_t data_int = *reinterpret_cast(*data); - -#ifndef WORDS_BIGENDIAN - data_int = ut_crc32_swap_byteorder(data_int); -#else - /* Currently we only support x86_64 (little endian) CPUs. In case - some big endian CPU supports a CRC32 instruction, then maybe we will - NOT need a byte order swap here. */ -#error Dont know how to handle big endian CPUs -#endif /* WORDS_BIGENDIAN */ - - *crc = ut_crc32_64_low_hw(*crc, data_int); - - *data += 8; - *len -= 8; -} - -/** Calculates CRC32 using hardware/CPU instructions. -@param[in] buf data over which to calculate CRC32 -@param[in] len data length -@return CRC-32C (polynomial 0x11EDC6F41) */ -uint32_t -ut_crc32_hw( - const byte* buf, - ulint len) -{ - uint32_t crc = 0xFFFFFFFFU; - - ut_a(ut_crc32_sse2_enabled); - - /* Calculate byte-by-byte up to an 8-byte aligned address. After - this consume the input 8-bytes at a time. */ - while (len > 0 && (reinterpret_cast(buf) & 7) != 0) { - ut_crc32_8_hw(&crc, &buf, &len); - } - - /* Perf testing - ./unittest/gunit/innodb/merge_innodb_tests-t --gtest_filter=ut0crc32.perf - on CPU "Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz" - with different N in "while (len >= N) {" shows: - N=16 - 2.867254 sec - 2.866860 sec - 2.867973 sec - - N=32 - 2.715725 sec - 2.713008 sec - 2.712520 sec - (5.36% speedup over N=16) - - N=64 - 2.634140 sec - 2.636558 sec - 2.636488 sec - (2.88% speedup over N=32) - - N=128 - 2.599534 sec - 2.599919 sec - 2.598035 sec - (1.39% speedup over N=64) - - N=256 - 2.576993 sec - 2.576748 sec - 2.575700 sec - (0.87% speedup over N=128) - - N=512 - 2.693928 sec - 2.691663 sec - 2.692142 sec - (4.51% slowdown over N=256) - */ - while (len >= 128) { - /* This call is repeated 16 times. 16 * 8 = 128. */ - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - } - - while (len >= 8) { - ut_crc32_64_hw(&crc, &buf, &len); - } - - while (len > 0) { - ut_crc32_8_hw(&crc, &buf, &len); - } - - return(~crc); -} - -/** Calculates CRC32 using hardware/CPU instructions. -This function uses big endian byte ordering when converting byte sequence to -integers. -@param[in] buf data over which to calculate CRC32 -@param[in] len data length -@return CRC-32C (polynomial 0x11EDC6F41) */ -uint32_t -ut_crc32_legacy_big_endian_hw( - const byte* buf, - ulint len) -{ - uint32_t crc = 0xFFFFFFFFU; - - ut_a(ut_crc32_sse2_enabled); - - /* Calculate byte-by-byte up to an 8-byte aligned address. After - this consume the input 8-bytes at a time. */ - while (len > 0 && (reinterpret_cast(buf) & 7) != 0) { - ut_crc32_8_hw(&crc, &buf, &len); - } - - while (len >= 128) { - /* This call is repeated 16 times. 16 * 8 = 128. */ - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - } - - while (len >= 8) { - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - } - - while (len > 0) { - ut_crc32_8_hw(&crc, &buf, &len); - } - - return(~crc); -} - -/** Calculates CRC32 using hardware/CPU instructions. -This function processes one byte at a time (very slow) and thus it does -not depend on the byte order of the machine. -@param[in] buf data over which to calculate CRC32 -@param[in] len data length -@return CRC-32C (polynomial 0x11EDC6F41) */ -uint32_t -ut_crc32_byte_by_byte_hw( - const byte* buf, - ulint len) -{ - uint32_t crc = 0xFFFFFFFFU; - - ut_a(ut_crc32_sse2_enabled); - - while (len > 0) { - ut_crc32_8_hw(&crc, &buf, &len); - } - - return(~crc); -} -#endif /* defined(__GNUC__) && defined(__x86_64__) */ - -/* CRC32 software implementation. */ - -/* Precalculated table used to generate the CRC32 if the CPU does not -have support for it */ -static uint32_t ut_crc32_slice8_table[8][256]; -static bool ut_crc32_slice8_table_initialized = false; - -/********************************************************************//** -Initializes the table that is used to generate the CRC32 if the CPU does -not have support for it. */ -static -void -ut_crc32_slice8_table_init() -/*========================*/ -{ - /* bit-reversed poly 0x1EDC6F41 (from SSE42 crc32 instruction) */ - static const uint32_t poly = 0x82f63b78; - uint32_t n; - uint32_t k; - uint32_t c; - - for (n = 0; n < 256; n++) { - c = n; - for (k = 0; k < 8; k++) { - c = (c & 1) ? (poly ^ (c >> 1)) : (c >> 1); - } - ut_crc32_slice8_table[0][n] = c; - } - - for (n = 0; n < 256; n++) { - c = ut_crc32_slice8_table[0][n]; - for (k = 1; k < 8; k++) { - c = ut_crc32_slice8_table[0][c & 0xFF] ^ (c >> 8); - ut_crc32_slice8_table[k][n] = c; - } - } - - ut_crc32_slice8_table_initialized = true; -} - -/** Calculate CRC32 over 8-bit data using a software implementation. -@param[in,out] crc crc32 checksum so far when this function is called, -when the function ends it will contain the new checksum -@param[in,out] data data to be checksummed, the pointer will be advanced -with 1 byte -@param[in,out] len remaining bytes, it will be decremented with 1 */ -inline -void -ut_crc32_8_sw( - uint32_t* crc, - const byte** data, - ulint* len) -{ - const uint8_t i = (*crc ^ (*data)[0]) & 0xFF; - - *crc = (*crc >> 8) ^ ut_crc32_slice8_table[0][i]; - - (*data)++; - (*len)--; -} - -/** Calculate CRC32 over a 64-bit integer using a software implementation. -@param[in] crc crc32 checksum so far -@param[in] data data to be checksummed -@return resulting checksum of crc + crc(data) */ -inline -uint32_t -ut_crc32_64_low_sw( - uint32_t crc, - uint64_t data) -{ - const uint64_t i = crc ^ data; - - return( - ut_crc32_slice8_table[7][(i ) & 0xFF] ^ - ut_crc32_slice8_table[6][(i >> 8) & 0xFF] ^ - ut_crc32_slice8_table[5][(i >> 16) & 0xFF] ^ - ut_crc32_slice8_table[4][(i >> 24) & 0xFF] ^ - ut_crc32_slice8_table[3][(i >> 32) & 0xFF] ^ - ut_crc32_slice8_table[2][(i >> 40) & 0xFF] ^ - ut_crc32_slice8_table[1][(i >> 48) & 0xFF] ^ - ut_crc32_slice8_table[0][(i >> 56)] - ); -} - -/** Calculate CRC32 over 64-bit byte string using a software implementation. -@param[in,out] crc crc32 checksum so far when this function is called, -when the function ends it will contain the new checksum -@param[in,out] data data to be checksummed, the pointer will be advanced -with 8 bytes -@param[in,out] len remaining bytes, it will be decremented with 8 */ -inline -void -ut_crc32_64_sw( - uint32_t* crc, - const byte** data, - ulint* len) -{ - uint64_t data_int = *reinterpret_cast(*data); - -#ifdef WORDS_BIGENDIAN - data_int = ut_crc32_swap_byteorder(data_int); -#endif /* WORDS_BIGENDIAN */ - - *crc = ut_crc32_64_low_sw(*crc, data_int); - - *data += 8; - *len -= 8; -} - -/** Calculate CRC32 over 64-bit byte string using a software implementation. -The byte string is converted to a 64-bit integer using big endian byte order. -@param[in,out] crc crc32 checksum so far when this function is called, -when the function ends it will contain the new checksum -@param[in,out] data data to be checksummed, the pointer will be advanced -with 8 bytes -@param[in,out] len remaining bytes, it will be decremented with 8 */ -inline -void -ut_crc32_64_legacy_big_endian_sw( - uint32_t* crc, - const byte** data, - ulint* len) -{ - uint64_t data_int = *reinterpret_cast(*data); - -#ifndef WORDS_BIGENDIAN - data_int = ut_crc32_swap_byteorder(data_int); -#endif /* WORDS_BIGENDIAN */ - - *crc = ut_crc32_64_low_sw(*crc, data_int); - - *data += 8; - *len -= 8; -} - -/** Calculates CRC32 in software, without using CPU instructions. -@param[in] buf data over which to calculate CRC32 -@param[in] len data length -@return CRC-32C (polynomial 0x11EDC6F41) */ -uint32_t -ut_crc32_sw( - const byte* buf, - ulint len) -{ - uint32_t crc = 0xFFFFFFFFU; - - ut_a(ut_crc32_slice8_table_initialized); - - /* Calculate byte-by-byte up to an 8-byte aligned address. After - this consume the input 8-bytes at a time. */ - while (len > 0 && (reinterpret_cast(buf) & 7) != 0) { - ut_crc32_8_sw(&crc, &buf, &len); - } - - while (len >= 128) { - /* This call is repeated 16 times. 16 * 8 = 128. */ - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - } - - while (len >= 8) { - ut_crc32_64_sw(&crc, &buf, &len); - } - - while (len > 0) { - ut_crc32_8_sw(&crc, &buf, &len); - } - - return(~crc); -} - -/** Calculates CRC32 in software, without using CPU instructions. -This function uses big endian byte ordering when converting byte sequence to -integers. -@param[in] buf data over which to calculate CRC32 -@param[in] len data length -@return CRC-32C (polynomial 0x11EDC6F41) */ -uint32_t -ut_crc32_legacy_big_endian_sw( - const byte* buf, - ulint len) -{ - uint32_t crc = 0xFFFFFFFFU; - - ut_a(ut_crc32_slice8_table_initialized); - - /* Calculate byte-by-byte up to an 8-byte aligned address. After - this consume the input 8-bytes at a time. */ - while (len > 0 && (reinterpret_cast(buf) & 7) != 0) { - ut_crc32_8_sw(&crc, &buf, &len); - } - - while (len >= 128) { - /* This call is repeated 16 times. 16 * 8 = 128. */ - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - } - - while (len >= 8) { - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - } - - while (len > 0) { - ut_crc32_8_sw(&crc, &buf, &len); - } - - return(~crc); -} - -/** Calculates CRC32 in software, without using CPU instructions. -This function processes one byte at a time (very slow) and thus it does -not depend on the byte order of the machine. -@param[in] buf data over which to calculate CRC32 -@param[in] len data length -@return CRC-32C (polynomial 0x11EDC6F41) */ -uint32_t -ut_crc32_byte_by_byte_sw( - const byte* buf, - ulint len) -{ - uint32_t crc = 0xFFFFFFFFU; - - ut_a(ut_crc32_slice8_table_initialized); - - while (len > 0) { - ut_crc32_8_sw(&crc, &buf, &len); - } - - return(~crc); -} - -/********************************************************************//** -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() -/*===========*/ -{ -#if defined(__GNUC__) && defined(__x86_64__) - uint32_t vend[3]; - uint32_t model; - uint32_t family; - uint32_t stepping; - uint32_t features_ecx; - uint32_t features_edx; - - ut_cpuid(vend, &model, &family, &stepping, - &features_ecx, &features_edx); - - /* Valgrind does not understand the CRC32 instructions: - - vex amd64->IR: unhandled instruction bytes: 0xF2 0x48 0xF 0x38 0xF0 0xA - valgrind: Unrecognised instruction at address 0xad3db5. - Your program just tried to execute an instruction that Valgrind - did not recognise. There are two possible reasons for this. - 1. Your program has a bug and erroneously jumped to a non-code - location. If you are running Memcheck and you just saw a - warning about a bad jump, it's probably your program's fault. - 2. The instruction is legitimate but Valgrind doesn't handle it, - i.e. it's Valgrind's fault. If you think this is the case or - you are not sure, please let us know and we'll try to fix it. - Either way, Valgrind will now raise a SIGILL signal which will - probably kill your program. - - */ -#ifndef UNIV_DEBUG_VALGRIND - ut_crc32_sse2_enabled = (features_ecx >> 20) & 1; -#endif /* UNIV_DEBUG_VALGRIND */ - - if (ut_crc32_sse2_enabled) { - ut_crc32 = ut_crc32_hw; - ut_crc32_legacy_big_endian = ut_crc32_legacy_big_endian_hw; - ut_crc32_byte_by_byte = ut_crc32_byte_by_byte_hw; - } - -#endif /* defined(__GNUC__) && defined(__x86_64__) */ - - if (!ut_crc32_sse2_enabled) { - ut_crc32_slice8_table_init(); - ut_crc32 = ut_crc32_sw; - ut_crc32_legacy_big_endian = ut_crc32_legacy_big_endian_sw; - ut_crc32_byte_by_byte = ut_crc32_byte_by_byte_sw; - } -} From d72298770184147434254052bd62230f47636af4 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 22 Mar 2016 11:25:09 +1100 Subject: [PATCH 02/12] Rename ut_crc32* function to ut_crc32c* Current ut_crc32 function represent the CRC32C algorithm so the rename reflects this. This change is in preparation for addition of CRC32 functions. The slice8 table is also abstracted in preparation for a CRC32 table. Software implementation also extended to allow for input CRC32 value to which the function will add to. --- include/ut0crc32.h | 12 +- mysys/ut0crc32.cc | 334 ++++++++++++++++++++--------------- storage/innobase/buf/buf0checksum.cc | 4 +- storage/innobase/dict/dict0mem.cc | 2 +- storage/innobase/fsp/fsp0fsp.cc | 4 +- storage/innobase/include/log0log.ic | 2 +- storage/innobase/page/page0zip.cc | 4 +- unittest/gunit/innodb/ut0crc32-t.cc | 34 ++-- 8 files changed, 225 insertions(+), 171 deletions(-) diff --git a/include/ut0crc32.h b/include/ut0crc32.h index 7fa3a99..1f8139fc 100644 --- a/include/ut0crc32.h +++ b/include/ut0crc32.h @@ -47,16 +47,16 @@ Calculates CRC32. or 0x1EDC6F41 without the high-order bit) */ typedef uint32_t (*ut_crc32_func_t)(const uint8* ptr, my_ulonglong len); -/** Pointer to CRC32 calculation function. */ -extern ut_crc32_func_t ut_crc32; +/** Pointer to CRC32C calculation function. */ +extern ut_crc32_func_t ut_crc32c; -/** Pointer to CRC32 calculation function, which uses big-endian byte order +/** Pointer to CRC32C calculation function, which uses big-endian byte order when converting byte strings to integers internally. */ -extern ut_crc32_func_t ut_crc32_legacy_big_endian; +extern ut_crc32_func_t ut_crc32c_legacy_big_endian; -/** Pointer to CRC32-byte-by-byte calculation function (byte order agnostic, +/** Pointer to CRC32C-byte-by-byte calculation function (byte order agnostic, but very slow). */ -extern ut_crc32_func_t ut_crc32_byte_by_byte; +extern ut_crc32_func_t ut_crc32c_byte_by_byte; /** Flag that tells whether the CPU supports CRC32 or not */ extern my_bool ut_crc32_sse2_enabled; diff --git a/mysys/ut0crc32.cc b/mysys/ut0crc32.cc index fb93ea7..9a67a2b 100644 --- a/mysys/ut0crc32.cc +++ b/mysys/ut0crc32.cc @@ -85,15 +85,15 @@ mysys/my_perf.c, contributed by Facebook under the following license. #include "ut0crc32.h" /** Pointer to CRC32 calculation function. */ -ut_crc32_func_t ut_crc32; +ut_crc32_func_t ut_crc32c; /** Pointer to CRC32 calculation function, which uses big-endian byte order when converting byte strings to integers internally. */ -ut_crc32_func_t ut_crc32_legacy_big_endian; +ut_crc32_func_t ut_crc32c_legacy_big_endian; /** Pointer to CRC32-byte-by-byte calculation function (byte order agnostic, but very slow). */ -ut_crc32_func_t ut_crc32_byte_by_byte; +ut_crc32_func_t ut_crc32c_byte_by_byte; /** Swap the byte order of an 8 byte integer. @param[in] i 8-byte integer @@ -158,7 +158,7 @@ with 1 byte @param[in,out] len remaining bytes, it will be decremented with 1 */ inline void -ut_crc32_8_hw( +ut_crc32c_8_hw( uint32* crc, const uint8** data, my_ulonglong* len) @@ -179,7 +179,7 @@ ut_crc32_8_hw( @return resulting checksum of crc + crc(data) */ inline uint32 -ut_crc32_64_low_hw( +ut_crc32c_64_low_hw( uint32 crc, uint64 data) { @@ -202,7 +202,7 @@ with 8 bytes @param[in,out] len remaining bytes, it will be decremented with 8 */ inline void -ut_crc32_64_hw( +ut_crc32c_64_hw( uint32* crc, const uint8** data, my_ulonglong* len) @@ -219,7 +219,7 @@ ut_crc32_64_hw( */ #endif /* WORDS_BIGENDIAN */ - *crc = ut_crc32_64_low_hw(*crc, data_int); + *crc = ut_crc32c_64_low_hw(*crc, data_int); *data += 8; *len -= 8; @@ -234,7 +234,7 @@ with 8 bytes @param[in,out] len remaining bytes, it will be decremented with 8 */ inline void -ut_crc32_64_legacy_big_endian_hw( +ut_crc32c_64_legacy_big_endian_hw( uint32* crc, const uint8** data, my_ulonglong* len) @@ -250,7 +250,7 @@ ut_crc32_64_legacy_big_endian_hw( #error Dont know how to handle big endian CPUs #endif /* WORDS_BIGENDIAN */ - *crc = ut_crc32_64_low_hw(*crc, data_int); + *crc = ut_crc32c_64_low_hw(*crc, data_int); *data += 8; *len -= 8; @@ -261,7 +261,7 @@ ut_crc32_64_legacy_big_endian_hw( @param[in] len data length @return CRC-32C (polynomial 0x11EDC6F41) */ uint32 -ut_crc32_hw( +ut_crc32c_hw( const uint8* buf, my_ulonglong len) { @@ -272,7 +272,7 @@ ut_crc32_hw( /* Calculate byte-by-byte up to an 8-byte aligned address. After this consume the input 8-bytes at a time. */ while (len > 0 && (reinterpret_cast(buf) & 7) != 0) { - ut_crc32_8_hw(&crc, &buf, &len); + ut_crc32c_8_hw(&crc, &buf, &len); } /* Perf testing @@ -316,30 +316,30 @@ ut_crc32_hw( */ while (len >= 128) { /* This call is repeated 16 times. 16 * 8 = 128. */ - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); - ut_crc32_64_hw(&crc, &buf, &len); + ut_crc32c_64_hw(&crc, &buf, &len); + ut_crc32c_64_hw(&crc, &buf, &len); + ut_crc32c_64_hw(&crc, &buf, &len); + ut_crc32c_64_hw(&crc, &buf, &len); + ut_crc32c_64_hw(&crc, &buf, &len); + ut_crc32c_64_hw(&crc, &buf, &len); + ut_crc32c_64_hw(&crc, &buf, &len); + ut_crc32c_64_hw(&crc, &buf, &len); + ut_crc32c_64_hw(&crc, &buf, &len); + ut_crc32c_64_hw(&crc, &buf, &len); + ut_crc32c_64_hw(&crc, &buf, &len); + ut_crc32c_64_hw(&crc, &buf, &len); + ut_crc32c_64_hw(&crc, &buf, &len); + ut_crc32c_64_hw(&crc, &buf, &len); + ut_crc32c_64_hw(&crc, &buf, &len); + ut_crc32c_64_hw(&crc, &buf, &len); } while (len >= 8) { - ut_crc32_64_hw(&crc, &buf, &len); + ut_crc32c_64_hw(&crc, &buf, &len); } while (len > 0) { - ut_crc32_8_hw(&crc, &buf, &len); + ut_crc32c_8_hw(&crc, &buf, &len); } return(~crc); @@ -352,7 +352,7 @@ integers. @param[in] len data length @return CRC-32C (polynomial 0x11EDC6F41) */ uint32 -ut_crc32_legacy_big_endian_hw( +ut_crc32c_legacy_big_endian_hw( const uint8* buf, my_ulonglong len) { @@ -363,35 +363,35 @@ ut_crc32_legacy_big_endian_hw( /* Calculate byte-by-byte up to an 8-byte aligned address. After this consume the input 8-bytes at a time. */ while (len > 0 && (reinterpret_cast(buf) & 7) != 0) { - ut_crc32_8_hw(&crc, &buf, &len); + ut_crc32c_8_hw(&crc, &buf, &len); } while (len >= 128) { /* This call is repeated 16 times. 16 * 8 = 128. */ - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32c_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32c_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32c_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32c_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32c_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32c_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32c_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32c_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32c_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32c_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32c_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32c_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32c_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32c_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32c_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32c_64_legacy_big_endian_hw(&crc, &buf, &len); } while (len >= 8) { - ut_crc32_64_legacy_big_endian_hw(&crc, &buf, &len); + ut_crc32c_64_legacy_big_endian_hw(&crc, &buf, &len); } while (len > 0) { - ut_crc32_8_hw(&crc, &buf, &len); + ut_crc32c_8_hw(&crc, &buf, &len); } return(~crc); @@ -404,7 +404,7 @@ not depend on the byte order of the machine. @param[in] len data length @return CRC-32C (polynomial 0x11EDC6F41) */ uint32 -ut_crc32_byte_by_byte_hw( +ut_crc32c_byte_by_byte_hw( const uint8* buf, my_ulonglong len) { @@ -413,7 +413,7 @@ ut_crc32_byte_by_byte_hw( DBUG_ASSERT(ut_crc32_sse2_enabled); while (len > 0) { - ut_crc32_8_hw(&crc, &buf, &len); + ut_crc32c_8_hw(&crc, &buf, &len); } return(~crc); @@ -424,19 +424,17 @@ ut_crc32_byte_by_byte_hw( /* Precalculated table used to generate the CRC32 if the CPU does not have support for it */ -static uint32 ut_crc32_slice8_table[8][256]; -static bool ut_crc32_slice8_table_initialized = false; +static uint32 ut_crc32c_slice8_table[8][256]; +static bool ut_crc32c_slice8_table_initialized = false; /********************************************************************//** Initializes the table that is used to generate the CRC32 if the CPU does not have support for it. */ static void -ut_crc32_slice8_table_init() +ut_crc32_slice8_table_init(const uint32 poly, uint32 slice8_table[8][256]) /*========================*/ { - /* bit-reversed poly 0x1EDC6F41 (from SSE42 crc32 instruction) */ - static const uint32 poly = 0x82f63b78; uint32 n; uint32 k; uint32 c; @@ -446,18 +444,26 @@ ut_crc32_slice8_table_init() for (k = 0; k < 8; k++) { c = (c & 1) ? (poly ^ (c >> 1)) : (c >> 1); } - ut_crc32_slice8_table[0][n] = c; + slice8_table[0][n] = c; } for (n = 0; n < 256; n++) { - c = ut_crc32_slice8_table[0][n]; + c = slice8_table[0][n]; for (k = 1; k < 8; k++) { - c = ut_crc32_slice8_table[0][c & 0xFF] ^ (c >> 8); - ut_crc32_slice8_table[k][n] = c; + c = slice8_table[0][c & 0xFF] ^ (c >> 8); + slice8_table[k][n] = c; } } +} + +static +void +ut_crc32c_slice8_table_init() +{ + /* bit-reversed poly 0x1EDC6F41 for CRC32C */ + ut_crc32_slice8_table_init(0x82f63b78, ut_crc32c_slice8_table); - ut_crc32_slice8_table_initialized = true; + ut_crc32c_slice8_table_initialized = true; } /** Calculate CRC32 over 8-bit data using a software implementation. @@ -471,11 +477,12 @@ void ut_crc32_8_sw( uint32* crc, const uint8** data, - my_ulonglong* len) + my_ulonglong* len, + uint32 slice8_table[8][256]) { const uint8_t i = (*crc ^ (*data)[0]) & 0xFF; - *crc = (*crc >> 8) ^ ut_crc32_slice8_table[0][i]; + *crc = (*crc >> 8) ^ slice8_table[0][i]; (*data)++; (*len)--; @@ -489,19 +496,20 @@ inline uint32 ut_crc32_64_low_sw( uint32 crc, - uint64 data) + uint64 data, + uint32 slice8_table[8][256]) { const uint64 i = crc ^ data; return( - ut_crc32_slice8_table[7][(i ) & 0xFF] ^ - ut_crc32_slice8_table[6][(i >> 8) & 0xFF] ^ - ut_crc32_slice8_table[5][(i >> 16) & 0xFF] ^ - ut_crc32_slice8_table[4][(i >> 24) & 0xFF] ^ - ut_crc32_slice8_table[3][(i >> 32) & 0xFF] ^ - ut_crc32_slice8_table[2][(i >> 40) & 0xFF] ^ - ut_crc32_slice8_table[1][(i >> 48) & 0xFF] ^ - ut_crc32_slice8_table[0][(i >> 56)] + slice8_table[7][(i ) & 0xFF] ^ + slice8_table[6][(i >> 8) & 0xFF] ^ + slice8_table[5][(i >> 16) & 0xFF] ^ + slice8_table[4][(i >> 24) & 0xFF] ^ + slice8_table[3][(i >> 32) & 0xFF] ^ + slice8_table[2][(i >> 40) & 0xFF] ^ + slice8_table[1][(i >> 48) & 0xFF] ^ + slice8_table[0][(i >> 56)] ); } @@ -516,7 +524,8 @@ void ut_crc32_64_sw( uint32* crc, const uint8** data, - my_ulonglong* len) + my_ulonglong* len, + uint32 slice8_table[8][256]) { uint64 data_int = *reinterpret_cast(*data); @@ -524,7 +533,7 @@ ut_crc32_64_sw( data_int = ut_crc32_swap_byteorder(data_int); #endif /* WORDS_BIGENDIAN */ - *crc = ut_crc32_64_low_sw(*crc, data_int); + *crc = ut_crc32_64_low_sw(*crc, data_int, slice8_table); *data += 8; *len -= 8; @@ -542,7 +551,8 @@ void ut_crc32_64_legacy_big_endian_sw( uint32* crc, const uint8** data, - my_ulonglong* len) + my_ulonglong* len, + uint32 slice8_table[8][256]) { uint64 data_int = *reinterpret_cast(*data); @@ -550,136 +560,180 @@ ut_crc32_64_legacy_big_endian_sw( data_int = ut_crc32_swap_byteorder(data_int); #endif /* WORDS_BIGENDIAN */ - *crc = ut_crc32_64_low_sw(*crc, data_int); + *crc = ut_crc32_64_low_sw(*crc, data_int, slice8_table); *data += 8; *len -= 8; } /** Calculates CRC32 in software, without using CPU instructions. +@param[in] crc_arg crc so far which we are adding to @param[in] buf data over which to calculate CRC32 @param[in] len data length -@return CRC-32C (polynomial 0x11EDC6F41) */ +@param[in] slice8_table data table that defines the crc polnominal +@return CRC */ +inline +static uint32 -ut_crc32_sw( +ut_crc32_slice8_common_sw( + uint32 crc_arg, const uint8* buf, - my_ulonglong len) + my_ulonglong len, + uint32 slice8_table[8][256]) { - uint32 crc = 0xFFFFFFFFU; - - DBUG_ASSERT(ut_crc32_slice8_table_initialized); + uint32 crc = crc_arg ^ 0xFFFFFFFFU; /* Calculate byte-by-byte up to an 8-byte aligned address. After this consume the input 8-bytes at a time. */ while (len > 0 && (reinterpret_cast(buf) & 7) != 0) { - ut_crc32_8_sw(&crc, &buf, &len); + ut_crc32_8_sw(&crc, &buf, &len, slice8_table); } while (len >= 128) { /* This call is repeated 16 times. 16 * 8 = 128. */ - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); - ut_crc32_64_sw(&crc, &buf, &len); + ut_crc32_64_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_sw(&crc, &buf, &len, slice8_table); } while (len >= 8) { - ut_crc32_64_sw(&crc, &buf, &len); + ut_crc32_64_sw(&crc, &buf, &len, slice8_table); } while (len > 0) { - ut_crc32_8_sw(&crc, &buf, &len); + ut_crc32_8_sw(&crc, &buf, &len, slice8_table); } return(~crc); } +uint32 +ut_crc32c_sw( + const uint8* buf, + my_ulonglong len) +{ + DBUG_ASSERT(ut_crc32c_slice8_table_initialized); + + return ut_crc32_slice8_common_sw(0UL, buf, len, ut_crc32c_slice8_table); +} + /** Calculates CRC32 in software, without using CPU instructions. This function uses big endian byte ordering when converting byte sequence to integers. +@param[in] crc_arg crc so far which we are adding to @param[in] buf data over which to calculate CRC32 @param[in] len data length -@return CRC-32C (polynomial 0x11EDC6F41) */ +@param[in] slice8_table data table that defines the crc polnominal +@return CRC */ +inline +static uint32 -ut_crc32_legacy_big_endian_sw( +ut_crc32_legacy_big_endian_slice8_common_sw( + uint32 crc_arg, const uint8* buf, - my_ulonglong len) + my_ulonglong len, + uint32 slice8_table[8][256]) { - uint32 crc = 0xFFFFFFFFU; - - DBUG_ASSERT(ut_crc32_slice8_table_initialized); + uint32 crc = crc_arg ^ 0xFFFFFFFFU; /* Calculate byte-by-byte up to an 8-byte aligned address. After this consume the input 8-bytes at a time. */ while (len > 0 && (reinterpret_cast(buf) & 7) != 0) { - ut_crc32_8_sw(&crc, &buf, &len); + ut_crc32_8_sw(&crc, &buf, &len, slice8_table); } while (len >= 128) { /* This call is repeated 16 times. 16 * 8 = 128. */ - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len, slice8_table); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len, slice8_table); } while (len >= 8) { - ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len); + ut_crc32_64_legacy_big_endian_sw(&crc, &buf, &len, slice8_table); } while (len > 0) { - ut_crc32_8_sw(&crc, &buf, &len); + ut_crc32_8_sw(&crc, &buf, &len, slice8_table); } return(~crc); } +uint32 +ut_crc32c_legacy_big_endian_sw( + const uint8* buf, + my_ulonglong len) +{ + DBUG_ASSERT(ut_crc32c_slice8_table_initialized); + + return ut_crc32_legacy_big_endian_slice8_common_sw(0UL, buf, len, + ut_crc32c_slice8_table); +} + /** Calculates CRC32 in software, without using CPU instructions. This function processes one byte at a time (very slow) and thus it does not depend on the byte order of the machine. +@param[in] crc_arg crc so far which we are adding to @param[in] buf data over which to calculate CRC32 @param[in] len data length -@return CRC-32C (polynomial 0x11EDC6F41) */ +@param[in] slice8_table data table that defines the crc polnominal +@return CRC */ +inline +static uint32 -ut_crc32_byte_by_byte_sw( +ut_crc32_byte_by_byte_common_sw( + uint32 crc_arg, const uint8* buf, - my_ulonglong len) + my_ulonglong len, + uint32 slice8_table[8][256]) { - uint32 crc = 0xFFFFFFFFU; - - DBUG_ASSERT(ut_crc32_slice8_table_initialized); + uint32 crc = crc_arg ^ 0xFFFFFFFFU; while (len > 0) { - ut_crc32_8_sw(&crc, &buf, &len); + ut_crc32_8_sw(&crc, &buf, &len, slice8_table); } return(~crc); } +uint32 +ut_crc32c_byte_by_byte_sw( + const uint8* buf, + my_ulonglong len) +{ + DBUG_ASSERT(ut_crc32c_slice8_table_initialized); + + return ut_crc32_byte_by_byte_common_sw(0UL, buf, len, + ut_crc32c_slice8_table); +} + /********************************************************************//** Initializes the data structures used by ut_crc32*(). Does not do any allocations, would not hurt if called twice, but would be pointless. */ @@ -719,17 +773,17 @@ ut_crc32_init() #endif /* UNIV_DEBUG_VALGRIND */ if (ut_crc32_sse2_enabled) { - ut_crc32 = ut_crc32_hw; - ut_crc32_legacy_big_endian = ut_crc32_legacy_big_endian_hw; - ut_crc32_byte_by_byte = ut_crc32_byte_by_byte_hw; + ut_crc32c = ut_crc32c_hw; + ut_crc32c_legacy_big_endian = ut_crc32c_legacy_big_endian_hw; + ut_crc32c_byte_by_byte = ut_crc32c_byte_by_byte_hw; } #endif /* defined(__GNUC__) && defined(__x86_64__) */ if (!ut_crc32_sse2_enabled) { - ut_crc32_slice8_table_init(); - ut_crc32 = ut_crc32_sw; - ut_crc32_legacy_big_endian = ut_crc32_legacy_big_endian_sw; - ut_crc32_byte_by_byte = ut_crc32_byte_by_byte_sw; + ut_crc32c_slice8_table_init(); + ut_crc32c = ut_crc32c_sw; + ut_crc32c_legacy_big_endian = ut_crc32c_legacy_big_endian_sw; + ut_crc32c_byte_by_byte = ut_crc32c_byte_by_byte_sw; } } diff --git a/storage/innobase/buf/buf0checksum.cc b/storage/innobase/buf/buf0checksum.cc index fca5ad4..9547f17 100644 --- a/storage/innobase/buf/buf0checksum.cc +++ b/storage/innobase/buf/buf0checksum.cc @@ -63,8 +63,8 @@ buf_calc_page_crc32( there we store the old formula checksum. */ ut_crc32_func_t crc32_func = use_legacy_big_endian - ? ut_crc32_legacy_big_endian - : ut_crc32; + ? ut_crc32c_legacy_big_endian + : ut_crc32c; const uint32_t c1 = crc32_func( page + FIL_PAGE_OFFSET, diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc index 850b6a0..7d9f303 100644 --- a/storage/innobase/dict/dict0mem.cc +++ b/storage/innobase/dict/dict0mem.cc @@ -842,7 +842,7 @@ dict_mem_init(void) const byte* buf = reinterpret_cast(&now); - dict_temp_file_num = ut_crc32(buf, sizeof(now)); + dict_temp_file_num = ut_crc32c(buf, sizeof(now)); DBUG_PRINT("dict_mem_init", ("Starting Temporary file number is " UINT32PF, diff --git a/storage/innobase/fsp/fsp0fsp.cc b/storage/innobase/fsp/fsp0fsp.cc index 7f1b718..1cb18f4 100644 --- a/storage/innobase/fsp/fsp0fsp.cc +++ b/storage/innobase/fsp/fsp0fsp.cc @@ -966,7 +966,7 @@ fsp_header_fill_encryption_info( ptr += ENCRYPTION_KEY_LEN * 2; /* Write checksum bytes. */ - crc = ut_crc32(key_info, ENCRYPTION_KEY_LEN * 2); + crc = ut_crc32c(key_info, ENCRYPTION_KEY_LEN * 2); mach_write_to_4(ptr, crc); my_free(master_key); @@ -1240,7 +1240,7 @@ fsp_header_decode_encryption_info( ptr += ENCRYPTION_KEY_LEN * 2; crc1 = mach_read_from_4(ptr); - crc2 = ut_crc32(key_info, ENCRYPTION_KEY_LEN * 2); + crc2 = ut_crc32c(key_info, ENCRYPTION_KEY_LEN * 2); if (crc1 != crc2) { ib::error() << "Failed to decrpt encryption information," << " please check key file is not changed!"; diff --git a/storage/innobase/include/log0log.ic b/storage/innobase/include/log0log.ic index b6e5db1..60a8b88 100644 --- a/storage/innobase/include/log0log.ic +++ b/storage/innobase/include/log0log.ic @@ -237,7 +237,7 @@ ulint log_block_calc_checksum_crc32( const byte* block) { - return(ut_crc32(block, OS_FILE_LOG_BLOCK_SIZE - LOG_BLOCK_TRL_SIZE)); + return(ut_crc32c(block, OS_FILE_LOG_BLOCK_SIZE - LOG_BLOCK_TRL_SIZE)); } /** Calculates the checksum for a log block using the "no-op" algorithm. diff --git a/storage/innobase/page/page0zip.cc b/storage/innobase/page/page0zip.cc index a16cce7..cd7e056 100644 --- a/storage/innobase/page/page0zip.cc +++ b/storage/innobase/page/page0zip.cc @@ -4898,8 +4898,8 @@ page_zip_calc_checksum( ut_ad(size > FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID); ut_crc32_func_t crc32_func = use_legacy_big_endian - ? ut_crc32_legacy_big_endian - : ut_crc32; + ? ut_crc32c_legacy_big_endian + : ut_crc32c; const uint32_t crc32 = crc32_func( diff --git a/unittest/gunit/innodb/ut0crc32-t.cc b/unittest/gunit/innodb/ut0crc32-t.cc index 0e13081..be89841 100644 --- a/unittest/gunit/innodb/ut0crc32-t.cc +++ b/unittest/gunit/innodb/ut0crc32-t.cc @@ -2099,16 +2099,16 @@ init() ); } -/* test ut_crc32*() */ -TEST(ut0crc32, basic) +/* test ut_crc32c*() */ +TEST(ut0crc32c, basic) { init(); EXPECT_EQ(1090276284U, - ut_crc32((const byte*) "innodb", 6)); + ut_crc32c((const byte*) "innodb", 6)); EXPECT_EQ(1090276284U, - ut_crc32_legacy_big_endian((const byte*) "innodb", 6)); + ut_crc32c_legacy_big_endian((const byte*) "innodb", 6)); byte* buf = new byte[page_size + 7]; @@ -2120,42 +2120,42 @@ TEST(ut0crc32, basic) memcpy(p, page, page_size); - EXPECT_EQ(2400278014U, ut_crc32(p, page_size)); - EXPECT_EQ(2400278014U, ut_crc32_byte_by_byte(p, page_size)); + EXPECT_EQ(2400278014U, ut_crc32c(p, page_size)); + EXPECT_EQ(2400278014U, ut_crc32c_byte_by_byte(p, page_size)); /* Big endian results depend on the alignment. */ switch (reinterpret_cast(p) % 8) { case 0: EXPECT_EQ(930371176U, - ut_crc32_legacy_big_endian(p, page_size)); + ut_crc32c_legacy_big_endian(p, page_size)); break; case 1: EXPECT_EQ(3983560868U, - ut_crc32_legacy_big_endian(p, page_size)); + ut_crc32c_legacy_big_endian(p, page_size)); break; case 2: EXPECT_EQ(2706750077U, - ut_crc32_legacy_big_endian(p, page_size)); + ut_crc32c_legacy_big_endian(p, page_size)); break; case 3: EXPECT_EQ(1846753308U, - ut_crc32_legacy_big_endian(p, page_size)); + ut_crc32c_legacy_big_endian(p, page_size)); break; case 4: EXPECT_EQ(781941328U, - ut_crc32_legacy_big_endian(p, page_size)); + ut_crc32c_legacy_big_endian(p, page_size)); break; case 5: EXPECT_EQ(1972010982U, - ut_crc32_legacy_big_endian(p, page_size)); + ut_crc32c_legacy_big_endian(p, page_size)); break; case 6: EXPECT_EQ(185421206U, - ut_crc32_legacy_big_endian(p, page_size)); + ut_crc32c_legacy_big_endian(p, page_size)); break; case 7: EXPECT_EQ(745843327U, - ut_crc32_legacy_big_endian(p, page_size)); + ut_crc32c_legacy_big_endian(p, page_size)); break; } } @@ -2163,7 +2163,7 @@ TEST(ut0crc32, basic) delete[] buf; } -TEST(ut0crc32, perf) +TEST(ut0crc32c, perf) { init(); @@ -2194,7 +2194,7 @@ TEST(ut0crc32, perf) for (size_t i = 0; i < n_pages; i++) { ASSERT_EQ(3911978414U, - ut_crc32(p + i * page_size, page_size)); + ut_crc32c(p + i * page_size, page_size)); } } @@ -2208,7 +2208,7 @@ TEST(ut0crc32, perf) for (size_t i = 0; i < n_pages; i++) { ASSERT_EQ(281254546U, - ut_crc32_legacy_big_endian(p + i * page_size, + ut_crc32c_legacy_big_endian(p + i * page_size, page_size)); } } From fd594a871e6f23d091c28a13451455e9087cb40b Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 22 Mar 2016 13:38:14 +1100 Subject: [PATCH 03/12] initialize crc32 globally Also call crc32 init in independent programs like: * mysqlbinlog * myisampack * myisamchk --- client/mysqlbinlog.cc | 2 ++ extra/comp_err.c | 2 ++ include/ut0crc32.h | 11 ++++++++--- sql/mysqld.cc | 3 +++ storage/innobase/srv/srv0srv.cc | 3 --- storage/myisam/myisamchk.c | 2 ++ storage/myisam/myisampack.c | 2 ++ 7 files changed, 19 insertions(+), 6 deletions(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 4ca9419..46b42c7 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -59,6 +59,7 @@ static void warning(const char *format, ...) #include "sql_string.h" #include "my_decimal.h" #include "rpl_constants.h" +#include "ut0crc32.h" #include #include @@ -3321,6 +3322,7 @@ int main(int argc, char** argv) DBUG_ENTER("main"); DBUG_PROCESS(argv[0]); + ut_crc32_init(); my_init_time(); // for time functions tzset(); // set tzname /* diff --git a/extra/comp_err.c b/extra/comp_err.c index 0716710..2821ccd 100644 --- a/extra/comp_err.c +++ b/extra/comp_err.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #define MAX_ROWS 2000 @@ -174,6 +175,7 @@ int main(int argc, char *argv[]) struct languages *lang_head; DBUG_ENTER("main"); + ut_crc32_init(); charsets_dir= DEFAULT_CHARSET_DIR; my_umask_dir= 0777; if (get_options(&argc, &argv)) diff --git a/include/ut0crc32.h b/include/ut0crc32.h index 1f8139fc..7766b09 100644 --- a/include/ut0crc32.h +++ b/include/ut0crc32.h @@ -28,13 +28,14 @@ Created Aug 10, 2011 Vasil Dimov #include +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + /********************************************************************//** Initializes the data structures used by ut_crc32*(). Does not do any allocations, would not hurt if called twice, but would be pointless. */ /* from UNIV_INTERN in storage/innobase/include/univ.i */ -#if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(sun) || defined(__INTEL_COMPILER) -__attribute__((visibility ("hidden"))) -#endif void ut_crc32_init(); /*===========*/ @@ -61,4 +62,8 @@ extern ut_crc32_func_t ut_crc32c_byte_by_byte; /** Flag that tells whether the CPU supports CRC32 or not */ extern my_bool ut_crc32_sse2_enabled; +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif /* ut0crc32_h */ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 579fbb7..9f98614 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -65,6 +65,7 @@ // cached_table_definitions #include "sql_test.h" // mysql_print_status #include "item_create.h" // item_create_cleanup, item_create_init +#include "ut0crc32.h" // ut_crc32_init #include "sql_servers.h" // servers_free, servers_init #include "init.h" // unireg_init #include "derror.h" // init_errmessage @@ -4454,6 +4455,8 @@ int mysqld_main(int argc, char **argv) init_error_log(); + ut_crc32_init(); + /* Initialize audit interface globals. Audit plugins are inited later. */ mysql_audit_initialize(); diff --git a/storage/innobase/srv/srv0srv.cc b/storage/innobase/srv/srv0srv.cc index 2c0e09f..9104b77 100644 --- a/storage/innobase/srv/srv0srv.cc +++ b/storage/innobase/srv/srv0srv.cc @@ -70,7 +70,6 @@ Created 10/8/1995 Heikki Tuuri #include "trx0i_s.h" #include "trx0purge.h" #include "usr0sess.h" -#include "ut0crc32.h" #include "ut0mem.h" /* The following is the maximum allowed duration of a lock wait. */ @@ -1013,8 +1012,6 @@ srv_init(void) /* Initialize some INFORMATION SCHEMA internal structures */ trx_i_s_cache_init(trx_i_s_cache); - ut_crc32_init(); - dict_mem_init(); } diff --git a/storage/myisam/myisamchk.c b/storage/myisam/myisamchk.c index a801948..b9464cd 100644 --- a/storage/myisam/myisamchk.c +++ b/storage/myisam/myisamchk.c @@ -17,6 +17,7 @@ #include "fulltext.h" #include "my_default.h" +#include "ut0crc32.h" #include #include @@ -94,6 +95,7 @@ int main(int argc, char **argv) my_progname_short= my_progname+dirname_length(my_progname); + ut_crc32_init(); myisamchk_init(&check_param); check_param.opt_lock_memory=1; /* Lock memory if possible */ check_param.using_global_keycache = 0; diff --git a/storage/myisam/myisampack.c b/storage/myisam/myisampack.c index 925445d..c8d85b1 100644 --- a/storage/myisam/myisampack.c +++ b/storage/myisam/myisampack.c @@ -24,6 +24,7 @@ #include #include #include "mysys_err.h" +#include "ut0crc32.h" #ifndef __GNU_LIBRARY__ #define __GNU_LIBRARY__ /* Skip warnings in getopt.h */ #endif @@ -224,6 +225,7 @@ int main(int argc, char **argv) get_options(&argc,&argv); error=ok=isamchk_neaded=0; + ut_crc32_init(); if (join_table) { /* From 5e27a0c50dfad7bbbd812c2775274520dce9d7b7 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 22 Mar 2016 14:41:59 +1100 Subject: [PATCH 04/12] Add slice8 implementation of crc32 Also add extended ut_crc32_ex so crc32 can be calculted in blocks with a partially calculated crc32. --- include/ut0crc32.h | 7 +++++++ mysys/ut0crc32.cc | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/include/ut0crc32.h b/include/ut0crc32.h index 7766b09..a2b926f 100644 --- a/include/ut0crc32.h +++ b/include/ut0crc32.h @@ -59,6 +59,13 @@ extern ut_crc32_func_t ut_crc32c_legacy_big_endian; but very slow). */ extern ut_crc32_func_t ut_crc32c_byte_by_byte; +/* Pointer to CRC32 calculation function - polynominal 0x04C11DB7 */ +extern ut_crc32_func_t ut_crc32; + +typedef uint32 (*ut_crc32_ex_func_t)(uint32, const uint8* ptr, my_ulonglong len); +/* extended CRC32 function taking the partial CRC32 as an input */ +extern ut_crc32_ex_func_t ut_crc32_ex; + /** Flag that tells whether the CPU supports CRC32 or not */ extern my_bool ut_crc32_sse2_enabled; diff --git a/mysys/ut0crc32.cc b/mysys/ut0crc32.cc index 9a67a2b..eaf9ab4 100644 --- a/mysys/ut0crc32.cc +++ b/mysys/ut0crc32.cc @@ -84,17 +84,23 @@ mysys/my_perf.c, contributed by Facebook under the following license. #include "ut0crc32.h" -/** Pointer to CRC32 calculation function. */ +/** Pointer to CRC32C calculation function. */ ut_crc32_func_t ut_crc32c; -/** Pointer to CRC32 calculation function, which uses big-endian byte order +/** Pointer to CRC32C calculation function, which uses big-endian byte order when converting byte strings to integers internally. */ ut_crc32_func_t ut_crc32c_legacy_big_endian; -/** Pointer to CRC32-byte-by-byte calculation function (byte order agnostic, +/** Pointer to CRC32C-byte-by-byte calculation function (byte order agnostic, but very slow). */ ut_crc32_func_t ut_crc32c_byte_by_byte; +/** Pointer to CRC32 calculation function. */ +ut_crc32_func_t ut_crc32; + +/** Pointer to extended CRC32 calculation function. */ +ut_crc32_ex_func_t ut_crc32_ex; + /** Swap the byte order of an 8 byte integer. @param[in] i 8-byte integer @return 8-byte integer */ @@ -426,6 +432,8 @@ ut_crc32c_byte_by_byte_hw( have support for it */ static uint32 ut_crc32c_slice8_table[8][256]; static bool ut_crc32c_slice8_table_initialized = false; +static uint32 ut_crc32_slice8_table[8][256]; +static bool ut_crc32_slice8_table_initialized = false; /********************************************************************//** Initializes the table that is used to generate the CRC32 if the CPU does @@ -466,6 +474,16 @@ ut_crc32c_slice8_table_init() ut_crc32c_slice8_table_initialized = true; } +static +void +ut_crc32_slice8_table_init() +{ + /* bit reversed poly 0x04C11DB7 for real CRC */ + ut_crc32_slice8_table_init(0xEDB88320, ut_crc32_slice8_table); + + ut_crc32_slice8_table_initialized = true; +} + /** Calculate CRC32 over 8-bit data using a software implementation. @param[in,out] crc crc32 checksum so far when this function is called, when the function ends it will contain the new checksum @@ -630,6 +648,27 @@ ut_crc32c_sw( return ut_crc32_slice8_common_sw(0UL, buf, len, ut_crc32c_slice8_table); } +uint32 +ut_crc32_sw( + const uint8* buf, + my_ulonglong len) +{ + DBUG_ASSERT(ut_crc32_slice8_table_initialized); + + return ut_crc32_slice8_common_sw(0UL, buf, len, ut_crc32_slice8_table); +} + +uint32 +ut_crc32_ex_sw( + uint32 crc, + const uint8* buf, + my_ulonglong len) +{ + DBUG_ASSERT(ut_crc32_slice8_table_initialized); + + return ut_crc32_slice8_common_sw(crc, buf, len, ut_crc32_slice8_table); +} + /** Calculates CRC32 in software, without using CPU instructions. This function uses big endian byte ordering when converting byte sequence to integers. @@ -776,6 +815,10 @@ ut_crc32_init() ut_crc32c = ut_crc32c_hw; ut_crc32c_legacy_big_endian = ut_crc32c_legacy_big_endian_hw; ut_crc32c_byte_by_byte = ut_crc32c_byte_by_byte_hw; + + ut_crc32_slice8_table_init(); + ut_crc32 = ut_crc32_sw; + ut_crc32_ex = ut_crc32_ex_sw; } #endif /* defined(__GNUC__) && defined(__x86_64__) */ @@ -785,5 +828,9 @@ ut_crc32_init() ut_crc32c = ut_crc32c_sw; ut_crc32c_legacy_big_endian = ut_crc32c_legacy_big_endian_sw; ut_crc32c_byte_by_byte = ut_crc32c_byte_by_byte_sw; + + ut_crc32_slice8_table_init(); + ut_crc32 = ut_crc32_sw; + ut_crc32_ex = ut_crc32_ex_sw; } } From a99f37d96ed94ccda64cb658f5ab9b02aa62a825 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 22 Mar 2016 14:53:09 +1100 Subject: [PATCH 05/12] Add CRC32() tests --- mysql-test/r/func_math.result | 6 ++++++ mysql-test/t/func_math.test | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result index 1f4f18c..2150000 100644 --- a/mysql-test/r/func_math.result +++ b/mysql-test/r/func_math.result @@ -953,3 +953,9 @@ number Round(number, num_digits) > 0 Round(number, 3) > 0 1 1 1 0 0 0 DROP PROCEDURE test_round_fn; +# +# CRC32 tests +# +select CRC32(NULL), CRC32(''), CRC32('MySQL'), CRC32('mysql'), CRC32('01234567'), CRC32('012345678'); +CRC32(NULL) CRC32('') CRC32('MySQL') CRC32('mysql') CRC32('01234567') CRC32('012345678') +NULL 0 3259397556 2501908538 763378421 939184570 diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test index fc45241..fe1e4f6 100644 --- a/mysql-test/t/func_math.test +++ b/mysql-test/t/func_math.test @@ -683,3 +683,10 @@ DELIMITER ;| CALL test_round_fn(); DROP PROCEDURE test_round_fn; + + +--echo # +--echo # CRC32 tests +--echo # + +select CRC32(NULL), CRC32(''), CRC32('MySQL'), CRC32('mysql'), CRC32('01234567'), CRC32('012345678'); From b3e57ddef403017075ef8abf6c308fb4efe5093c Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 22 Mar 2016 15:00:22 +1100 Subject: [PATCH 06/12] Use ut_crc32 for CRC32 SQL function --- sql/item_strfunc.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 26d6563..78e579b 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -49,6 +49,7 @@ C_MODE_START C_MODE_END #include "template_utils.h" +#include "ut0crc32.h" #include "pfs_file_provider.h" #include "mysql/psi/mysql_file.h" @@ -4945,7 +4946,7 @@ longlong Item_func_crc32::val_int() return 0; /* purecov: inspected */ } null_value=0; - return (longlong) crc32(0L, (uchar*)res->ptr(), res->length()); + return (longlong) ut_crc32((uchar*)res->ptr(), res->length()); } #ifdef HAVE_COMPRESS From 5564a4564d19e376dfa99986b7296766ae3ff7e0 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 22 Mar 2016 18:13:29 +1100 Subject: [PATCH 07/12] Move crc32_init to init_server_components for embedded to initialize correctly --- sql/mysqld.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 9f98614..78b8c53 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -3698,6 +3698,8 @@ static int init_server_components() We need to call each of these following functions to ensure that all things are initialized so that unireg_abort() doesn't fail */ + ut_crc32_init(); + mdl_init(); partitioning_init(); if (table_def_init() | hostname_cache_init(host_cache_size)) @@ -4455,8 +4457,6 @@ int mysqld_main(int argc, char **argv) init_error_log(); - ut_crc32_init(); - /* Initialize audit interface globals. Audit plugins are inited later. */ mysql_audit_initialize(); From 3df8fe7862f537496f9bc1128e3181582516af91 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 22 Mar 2016 18:20:44 +1100 Subject: [PATCH 08/12] use ut_crc32_ex instead of zlib crc32 for my_checksum --- mysys/checksum.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mysys/checksum.c b/mysys/checksum.c index 87f3056..97dced3 100644 --- a/mysys/checksum.c +++ b/mysys/checksum.c @@ -16,7 +16,7 @@ #include #include -#include +#include "ut0crc32.h" /* Calculate a long checksum for a memoryblock. @@ -30,6 +30,6 @@ ha_checksum my_checksum(ha_checksum crc, const uchar *pos, size_t length) { - return (ha_checksum)crc32((uint)crc, pos, (uint)length); + return (ha_checksum)ut_crc32_ex((uint)crc, pos, (uint)length); } From a9869e86bb27be173bad0f9814a934726b75c83e Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 22 Mar 2016 18:51:57 +1100 Subject: [PATCH 09/12] use ut_crc32{,_ex} for binary log --- libbinlogevents/include/binlog_event.h | 19 ------------------- libbinlogevents/src/binlog_event.cpp | 7 +++---- sql/binlog.cc | 1 - sql/log_event.cc | 14 +++++++++----- sql/log_event.h | 9 ++++++++- sql/rpl_binlog_sender.cc | 6 +++--- sql/rpl_slave.cc | 11 +++++------ sql/rpl_utility.cc | 11 +++++------ sql/sql_table.cc | 8 ++++---- 9 files changed, 37 insertions(+), 49 deletions(-) diff --git a/libbinlogevents/include/binlog_event.h b/libbinlogevents/include/binlog_event.h index bb4219f..e0782f3 100644 --- a/libbinlogevents/include/binlog_event.h +++ b/libbinlogevents/include/binlog_event.h @@ -35,7 +35,6 @@ */ #include "byteorder.h" #include "wrapper_functions.h" -#include //for checksum calculations #include #include #include @@ -405,24 +404,6 @@ enum enum_binlog_checksum_alg #define BINLOG_CHECKSUM_ALG_DESC_LEN 1 /* 1 byte checksum alg descriptor */ #define LOG_EVENT_HEADER_SIZE 20 -/** - Calculate a long checksum for a memoryblock. - - @param crc start value for crc - @param pos pointer to memory block - @param length length of the block - - @return checksum for a memory block -*/ -inline uint32_t checksum_crc32(uint32_t crc, const unsigned char *pos, - size_t length) -{ - BAPI_ASSERT(length <= UINT_MAX); - return static_cast(crc32(static_cast(crc), pos, - static_cast(length))); -} - - /* Reads string from buf. diff --git a/libbinlogevents/src/binlog_event.cpp b/libbinlogevents/src/binlog_event.cpp index 65f2af3..4fd8a69 100644 --- a/libbinlogevents/src/binlog_event.cpp +++ b/libbinlogevents/src/binlog_event.cpp @@ -16,6 +16,7 @@ #include "binary_log_types.h" #include "statement_events.h" +#include "ut0crc32.h" #include #include @@ -253,11 +254,9 @@ bool Log_event_footer::event_checksum_test(unsigned char *event_buf, event_buf + event_len - BINLOG_CHECKSUM_LEN, sizeof(incoming)); incoming= le32toh(incoming); - computed= checksum_crc32(0L, NULL, 0); /* checksum the event content but not the checksum part itself */ - computed= binary_log::checksum_crc32(computed, - (const unsigned char*) event_buf, - event_len - BINLOG_CHECKSUM_LEN); + computed= ut_crc32((const unsigned char*) event_buf, + event_len - BINLOG_CHECKSUM_LEN); if (flags != 0) { diff --git a/sql/binlog.cc b/sql/binlog.cc index 6a07c3f..830539f 100644 --- a/sql/binlog.cc +++ b/sql/binlog.cc @@ -44,7 +44,6 @@ using std::max; using std::min; using std::string; using std::list; -using binary_log::checksum_crc32; #define FLAGSTR(V,F) ((V)&(F)?#F" ":"") #define LOG_PREFIX "ML" diff --git a/sql/log_event.cc b/sql/log_event.cc index 5f3ae12..51c7409 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -18,6 +18,7 @@ #include "base64.h" // base64_encode #include "binary_log_funcs.h" // my_timestamp_binary_length +#include "ut0crc32.h" #ifndef MYSQL_CLIENT #include "debug_sync.h" // debug_sync_set_action @@ -663,6 +664,10 @@ const char* Log_event::get_type_str() return get_type_str(get_type_code()); } +#ifdef MYSQL_CLIENT +Log_event::init_crc32::init_crc32() { ut_crc32_init(); } +static Log_event::init_crc32 Log_event_crc32; +#endif /* Log_event::Log_event() @@ -972,7 +977,7 @@ my_bool Log_event::need_checksum() bool Log_event::wrapper_my_b_safe_write(IO_CACHE* file, const uchar* buf, size_t size) { if (need_checksum() && size != 0) - crc= checksum_crc32(crc, buf, size); + crc= ut_crc32_ex(crc, buf, size); return my_b_safe_write(file, buf, size); } @@ -1046,7 +1051,6 @@ bool Log_event::write_header(IO_CACHE* file, size_t event_data_length) if (need_checksum()) { - crc= checksum_crc32(0L, NULL, 0); common_header->data_written += BINLOG_CHECKSUM_LEN; } @@ -1113,7 +1117,7 @@ bool Log_event::write_header(IO_CACHE* file, size_t event_data_length) common_header->flags &= ~LOG_EVENT_BINLOG_IN_USE_F; int2store(header + FLAGS_OFFSET, common_header->flags); } - crc= my_checksum(crc, header, LOG_EVENT_HEADER_LEN); + crc= ut_crc32(header, LOG_EVENT_HEADER_LEN); DBUG_RETURN( ret); } @@ -12649,10 +12653,10 @@ Incident_log_event::write_data_body(IO_CACHE *file) uchar tmp[1]; DBUG_ENTER("Incident_log_event::write_data_body"); tmp[0]= (uchar) message_length; - crc= checksum_crc32(crc, (uchar*) tmp, 1); + crc= ut_crc32_ex(crc, (uchar*) tmp, 1); if (message_length > 0) { - crc= checksum_crc32(crc, (uchar*) message, message_length); + crc= ut_crc32_ex(crc, (uchar*) message, message_length); // todo: report a bug on write_str accepts uint but treats it as uchar } DBUG_RETURN(write_str_at_most_255_bytes(file, message, (uint) message_length)); diff --git a/sql/log_event.h b/sql/log_event.h index 0a48fb1..602ac04 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -61,7 +61,6 @@ extern PSI_memory_key key_memory_Incident_log_event_message; extern PSI_memory_key key_memory_Rows_query_log_event_rows_query; /* Forward declarations */ using binary_log::enum_binlog_checksum_alg; -using binary_log::checksum_crc32; using binary_log::Log_event_type; using binary_log::Log_event_header; using binary_log::Log_event_footer; @@ -922,6 +921,14 @@ class Log_event const char* get_type_str(); /* Return start of query time or current time */ +#if defined(MYSQL_CLIENT) + class init_crc32 + { + public: + init_crc32(); + }; +#endif + #if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) /** Is called from get_mts_execution_mode() to diff --git a/sql/rpl_binlog_sender.cc b/sql/rpl_binlog_sender.cc index d0842be..eaefb28 100644 --- a/sql/rpl_binlog_sender.cc +++ b/sql/rpl_binlog_sender.cc @@ -24,6 +24,7 @@ #include "rpl_master.h" // opt_sporadic_binlog_dump_fail #include "rpl_reporting.h" // MAX_SLAVE_ERRMSG #include "sql_class.h" // THD +#include "ut0crc32.h" // checksum_crc32 #include "pfs_file_provider.h" #include "mysql/psi/mysql_file.h" @@ -31,7 +32,6 @@ #ifndef DBUG_OFF static uint binlog_dump_count= 0; #endif -using binary_log::checksum_crc32; const uint32 Binlog_sender::PACKET_MIN_SIZE= 4096; const uint32 Binlog_sender::PACKET_MAX_SIZE= UINT_MAX32; @@ -886,8 +886,8 @@ int Binlog_sender::fake_rotate_event(const char *next_log_file, inline void Binlog_sender::calc_event_checksum(uchar *event_ptr, size_t event_len) { - ha_checksum crc= checksum_crc32(0L, NULL, 0); - crc= checksum_crc32(crc, event_ptr, event_len - BINLOG_CHECKSUM_LEN); + ha_checksum crc; + crc= ut_crc32(event_ptr, event_len - BINLOG_CHECKSUM_LEN); int4store(event_ptr + event_len - BINLOG_CHECKSUM_LEN, crc); } diff --git a/sql/rpl_slave.cc b/sql/rpl_slave.cc index 5b42ef9..3022adc 100644 --- a/sql/rpl_slave.cc +++ b/sql/rpl_slave.cc @@ -51,6 +51,7 @@ #include "transaction.h" // trans_begin #include "tztime.h" // Time_zone #include "rpl_group_replication.h" +#include "ut0crc32.h" // Sic: Must be after mysqld.h to get the right ER macro. #include "errmsg.h" // CR_* @@ -63,7 +64,6 @@ using std::min; using std::max; -using binary_log::checksum_crc32; using binary_log::Log_event_header; #define FLAGSTR(V,F) ((V)&(F)?#F" ":"") @@ -7862,8 +7862,7 @@ bool queue_event(Master_info* mi,const char* buf, ulong event_len) int2store(ev_buf + FLAGS_OFFSET, uint2korr(ev_buf + FLAGS_OFFSET) | LOG_EVENT_IGNORABLE_F); /* Recalc event's CRC */ - ha_checksum ev_crc= checksum_crc32(0L, NULL, 0); - ev_crc= checksum_crc32(ev_crc, (const uchar *) ev_buf, + ha_checksum ev_crc= ut_crc32((const uchar *) ev_buf, event_len - BINLOG_CHECKSUM_LEN); int4store(&ev_buf[event_len - BINLOG_CHECKSUM_LEN], ev_crc); /* @@ -7965,14 +7964,14 @@ bool queue_event(Master_info* mi,const char* buf, ulong event_len) mi->rli->relay_log.relay_log_checksum_alg != binary_log::BINLOG_CHECKSUM_ALG_OFF) { - ha_checksum rot_crc= checksum_crc32(0L, NULL, 0); + ha_checksum rot_crc; event_len += BINLOG_CHECKSUM_LEN; memcpy(rot_buf, buf, event_len - BINLOG_CHECKSUM_LEN); int4store(&rot_buf[EVENT_LEN_OFFSET], uint4korr(rot_buf + EVENT_LEN_OFFSET) + BINLOG_CHECKSUM_LEN); - rot_crc= checksum_crc32(rot_crc, (const uchar *) rot_buf, - event_len - BINLOG_CHECKSUM_LEN); + rot_crc= ut_crc32((const uchar *) rot_buf, + event_len - BINLOG_CHECKSUM_LEN); int4store(&rot_buf[event_len - BINLOG_CHECKSUM_LEN], rot_crc); DBUG_ASSERT(event_len == uint4korr(&rot_buf[EVENT_LEN_OFFSET])); DBUG_ASSERT(mi->get_mi_description_event()->common_footer->checksum_alg == diff --git a/sql/rpl_utility.cc b/sql/rpl_utility.cc index f4c8f2e..84599fe 100644 --- a/sql/rpl_utility.cc +++ b/sql/rpl_utility.cc @@ -17,7 +17,7 @@ #ifndef MYSQL_CLIENT -#include "binlog_event.h" // checksum_crv32 +#include "ut0crc32.h" // ut_crc32 #include "template_utils.h" // delete_container_pointers #include "field.h" // Field #include "log.h" // sql_print_error @@ -30,7 +30,6 @@ using std::min; using std::max; -using binary_log::checksum_crc32; /** Function to compare two size_t integers for their relative @@ -1167,7 +1166,7 @@ my_hash_value_type Hash_slave_rows::make_hash_key(TABLE *table, MY_BITMAP *cols) { DBUG_ENTER("Hash_slave_rows::make_hash_key"); - ha_checksum crc= 0L; + ha_checksum crc=0; uchar *record= table->record[0]; uchar saved_x= 0, saved_filler= 0; @@ -1207,7 +1206,7 @@ Hash_slave_rows::make_hash_key(TABLE *table, MY_BITMAP *cols) */ if (bitmap_is_set_all(cols)) { - crc= checksum_crc32(crc, table->null_flags, table->s->null_bytes); + crc= ut_crc32(table->null_flags, table->s->null_bytes); DBUG_PRINT("debug", ("make_hash_entry: hash after null_flags: %u", crc)); } @@ -1236,11 +1235,11 @@ Hash_slave_rows::make_hash_key(TABLE *table, MY_BITMAP *cols) { String tmp; f->val_str(&tmp); - crc= checksum_crc32(crc, (uchar*) tmp.ptr(), tmp.length()); + crc= ut_crc32_ex(crc, (uchar*) tmp.ptr(), tmp.length()); break; } default: - crc= checksum_crc32(crc, f->ptr, f->data_length()); + crc= ut_crc32_ex(crc, f->ptr, f->data_length()); break; } #ifndef DBUG_OFF diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 14eb274..36764d4 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -61,6 +61,7 @@ #include "binlog.h" #include "sql_tablespace.h" // check_tablespace_name()) #include "item_timefunc.h" // Item_func_now_local +#include "ut0crc32.h" #include "pfs_file_provider.h" #include "mysql/psi/mysql_file.h" @@ -68,7 +69,6 @@ #include using std::max; using std::min; -using binary_log::checksum_crc32; #define ER_THD_OR_DEFAULT(thd,X) ((thd) ? ER_THD(thd, X) : ER_DEFAULT(X)) @@ -10363,7 +10363,7 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables, if (!(t->s->db_create_options & HA_OPTION_PACK_RECORD)) t->record[0][0] |= 1; - row_crc= checksum_crc32(row_crc, t->record[0], t->s->null_bytes); + row_crc= ut_crc32_ex(row_crc, t->record[0], t->s->null_bytes); } for (uint i= 0; i < t->s->fields; i++ ) @@ -10383,12 +10383,12 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables, { String tmp; f->val_str(&tmp); - row_crc= checksum_crc32(row_crc, (uchar*) tmp.ptr(), + row_crc= ut_crc32_ex(row_crc, (uchar*) tmp.ptr(), tmp.length()); break; } default: - row_crc= checksum_crc32(row_crc, f->ptr, f->pack_length()); + row_crc= ut_crc32_ex(row_crc, f->ptr, f->pack_length()); break; } } From e53a7c60a664e2ef3d742215a34bcbd9ed6b672d Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Wed, 23 Mar 2016 11:07:38 +1100 Subject: [PATCH 10/12] Use char* to describe crc32 implemenation --- include/ut0crc32.h | 4 ++-- mysys/ut0crc32.cc | 11 ++++++----- storage/innobase/srv/srv0start.cc | 3 +-- unittest/gunit/innodb/ut0crc32-t.cc | 6 ++---- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/include/ut0crc32.h b/include/ut0crc32.h index a2b926f..949f6ea 100644 --- a/include/ut0crc32.h +++ b/include/ut0crc32.h @@ -66,8 +66,8 @@ typedef uint32 (*ut_crc32_ex_func_t)(uint32, const uint8* ptr, my_ulonglong len) /* extended CRC32 function taking the partial CRC32 as an input */ extern ut_crc32_ex_func_t ut_crc32_ex; -/** Flag that tells whether the CPU supports CRC32 or not */ -extern my_bool ut_crc32_sse2_enabled; +/** Text description of CRC32(C) implementation */ +extern const char *ut_crc32_implementation; #ifdef __cplusplus } diff --git a/mysys/ut0crc32.cc b/mysys/ut0crc32.cc index eaf9ab4..6f154e4 100644 --- a/mysys/ut0crc32.cc +++ b/mysys/ut0crc32.cc @@ -101,6 +101,9 @@ ut_crc32_func_t ut_crc32; /** Pointer to extended CRC32 calculation function. */ ut_crc32_ex_func_t ut_crc32_ex; +/** Text description of CRC32 implementation */ +const char *ut_crc32_implementation = NULL; + /** Swap the byte order of an 8 byte integer. @param[in] i 8-byte integer @return 8-byte integer */ @@ -121,9 +124,6 @@ ut_crc32_swap_byteorder( /* CRC32 hardware implementation. */ -/* Flag that tells whether the CPU supports CRC32 or not */ -my_bool ut_crc32_sse2_enabled = false; - #if defined(__GNUC__) && defined(__x86_64__) /********************************************************************//** Fetches CPU info */ @@ -273,8 +273,6 @@ ut_crc32c_hw( { uint32 crc = 0xFFFFFFFFU; - DBUG_ASSERT(ut_crc32_sse2_enabled); - /* Calculate byte-by-byte up to an 8-byte aligned address. After this consume the input 8-bytes at a time. */ while (len > 0 && (reinterpret_cast(buf) & 7) != 0) { @@ -780,6 +778,7 @@ void ut_crc32_init() /*===========*/ { + my_bool ut_crc32_sse2_enabled = false; #if defined(__GNUC__) && defined(__x86_64__) uint32 vend[3]; uint32 model; @@ -819,6 +818,7 @@ ut_crc32_init() ut_crc32_slice8_table_init(); ut_crc32 = ut_crc32_sw; ut_crc32_ex = ut_crc32_ex_sw; + ut_crc32_implementation = "Using SSE2 crc32c instructions"; } #endif /* defined(__GNUC__) && defined(__x86_64__) */ @@ -832,5 +832,6 @@ ut_crc32_init() ut_crc32_slice8_table_init(); ut_crc32 = ut_crc32_sw; ut_crc32_ex = ut_crc32_ex_sw; + ut_crc32_implementation = "Using generic slice8 crc32 implemenation"; } } diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index d08e836..2257bc5 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -1673,8 +1673,7 @@ innobase_start_or_create_for_mysql(void) srv_boot(); - ib::info() << (ut_crc32_sse2_enabled ? "Using" : "Not using") - << " CPU crc32 instructions"; + ib::info() << ut_crc32_implementation; if (!srv_read_only_mode) { diff --git a/unittest/gunit/innodb/ut0crc32-t.cc b/unittest/gunit/innodb/ut0crc32-t.cc index be89841..9dfa515 100644 --- a/unittest/gunit/innodb/ut0crc32-t.cc +++ b/unittest/gunit/innodb/ut0crc32-t.cc @@ -2087,10 +2087,8 @@ init() { ut_crc32_init(); - fprintf(stderr, "Using %s, CPU is %s-endian ", - ut_crc32_sse2_enabled - ? "hardware CPU crc32 instructions" - : "software crc32 implementation", + fprintf(stderr, "%s, CPU is %s-endian ", + ut_crc32_implementation, #ifdef WORDS_BIGENDIAN "big" #else /* WORDS_BIGENDIAN */ From 8e80dbaac5d702957eff3740878ddcedc6e23125 Mon Sep 17 00:00:00 2001 From: Anton Blanchard Date: Wed, 23 Mar 2016 11:13:04 +1100 Subject: [PATCH 11/12] Bug#74776: Add POWER8 optimized crc32 and crc32c Based on implementation: https://github.com/antonblanchard/crc32-vpmsum --- mysys/CMakeLists.txt | 11 + mysys/crc32_power8/crc32.S | 14 + mysys/crc32_power8/crc32.iS | 735 +++++++++++++++++++++++++++++ mysys/crc32_power8/crc32_constants.h | 835 +++++++++++++++++++++++++++++++++ mysys/crc32_power8/crc32_wrapper.c | 75 +++ mysys/crc32_power8/crc32_wrapper.ic | 52 +++ mysys/crc32_power8/crc32c.S | 14 + mysys/crc32_power8/crc32c_constants.h | 837 ++++++++++++++++++++++++++++++++++ mysys/crc32_power8/crc32c_wrapper.c | 78 ++++ mysys/crc32_power8/ppc-opcode.h | 23 + mysys/ut0crc32.cc | 87 +++- 11 files changed, 2757 insertions(+), 4 deletions(-) create mode 100644 mysys/crc32_power8/crc32.S create mode 100644 mysys/crc32_power8/crc32.iS create mode 100644 mysys/crc32_power8/crc32_constants.h create mode 100644 mysys/crc32_power8/crc32_wrapper.c create mode 100644 mysys/crc32_power8/crc32_wrapper.ic create mode 100644 mysys/crc32_power8/crc32c.S create mode 100644 mysys/crc32_power8/crc32c_constants.h create mode 100644 mysys/crc32_power8/crc32c_wrapper.c create mode 100644 mysys/crc32_power8/ppc-opcode.h diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt index bb325ca..1ad4f71 100644 --- a/mysys/CMakeLists.txt +++ b/mysys/CMakeLists.txt @@ -36,6 +36,17 @@ SET(MYSYS_SOURCES array.c charset-def.c charset.c checksum.c my_rdtsc.c psi_noop.c my_syslog.c my_chmod.c my_thread.c ut0crc32.cc) +IF(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le") + enable_language(ASM) + INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/mysys/crc32_power8) + LIST(APPEND MYSYS_SOURCES + crc32_power8/crc32.S + crc32_power8/crc32c.S + crc32_power8/crc32_wrapper.c + crc32_power8/crc32c_wrapper.c + ) +ENDIF() + IF (WIN32) LIST(APPEND MYSYS_SOURCES my_conio.c diff --git a/mysys/crc32_power8/crc32.S b/mysys/crc32_power8/crc32.S new file mode 100644 index 0000000..46a2733 --- /dev/null +++ b/mysys/crc32_power8/crc32.S @@ -0,0 +1,14 @@ +#ifdef __powerpc__ + +#define CONSTANTS .crc32_constants +#define SHORT_CONSTANTS .crc32_short_constants +#define BARRETT_CONSTANTS .crc32_barrett_constants + +#include "crc32_constants.h" + +#define __F __crc32_vpmsum + +#include "crc32.iS" + +#endif + diff --git a/mysys/crc32_power8/crc32.iS b/mysys/crc32_power8/crc32.iS new file mode 100644 index 0000000..06f1543 --- /dev/null +++ b/mysys/crc32_power8/crc32.iS @@ -0,0 +1,735 @@ +/* + * Calculate the checksum of data that is 16 byte aligned and a multiple of + * 16 bytes. + * + * The first step is to reduce it to 1024 bits. We do this in 8 parallel + * chunks in order to mask the latency of the vpmsum instructions. If we + * have more than 32 kB of data to checksum we repeat this step multiple + * times, passing in the previous 1024 bits. + * + * The next step is to reduce the 1024 bits to 64 bits. This step adds + * 32 bits of 0s to the end - this matches what a CRC does. We just + * calculate constants that land the data in this 32 bits. + * + * We then use fixed point Barrett reduction to compute a mod n over GF(2) + * for n = CRC using POWER8 instructions. We use x = 32. + * + * http://en.wikipedia.org/wiki/Barrett_reduction + * + * Copyright (C) 2015 Anton Blanchard , IBM + * + * 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; either version + * 2 of the License, or (at your option) any later version. + */ + +#ifdef __powerpc__ + +#include +#include "ppc-opcode.h" + +#undef toc + +#ifndef r1 +#define r1 1 +#endif + +#ifndef r2 +#define r2 2 +#endif + + .section .rodata +.balign 16 + +.byteswap_constant: + /* byte reverse permute constant */ + .octa 0x0F0E0D0C0B0A09080706050403020100 + + .text + +#define off16 r25 +#define off32 r26 +#define off48 r27 +#define off64 r28 +#define off80 r29 +#define off96 r30 +#define off112 r31 + +#define const1 v24 +#define const2 v25 + +#define byteswap v26 +#define mask_32bit v27 +#define mask_64bit v28 +#define zeroes v29 + +#ifdef BYTESWAP_DATA +#define VPERM(A, B, C, D) vperm A, B, C, D +#else +#define VPERM(A, B, C, D) +#endif + +/* unsigned int __crc32_vpmsum(unsigned int crc, void *p, unsigned long len) */ +FUNC_START(__F) + std r31,-8(r1) + std r30,-16(r1) + std r29,-24(r1) + std r28,-32(r1) + std r27,-40(r1) + std r26,-48(r1) + std r25,-56(r1) + + li off16,16 + li off32,32 + li off48,48 + li off64,64 + li off80,80 + li off96,96 + li off112,112 + li r0,0 + + /* Enough room for saving 10 non volatile VMX registers */ + subi r6,r1,56+10*16 + subi r7,r1,56+2*16 + + stvx v20,0,r6 + stvx v21,off16,r6 + stvx v22,off32,r6 + stvx v23,off48,r6 + stvx v24,off64,r6 + stvx v25,off80,r6 + stvx v26,off96,r6 + stvx v27,off112,r6 + stvx v28,0,r7 + stvx v29,off16,r7 + + mr r10,r3 + + vxor zeroes,zeroes,zeroes + vspltisw v0,-1 + + vsldoi mask_32bit,zeroes,v0,4 + vsldoi mask_64bit,zeroes,v0,8 + + /* Get the initial value into v8 */ + vxor v8,v8,v8 + MTVRD(v8, r3) + + vsldoi v8,zeroes,v8,8 /* shift into bottom 32 bits */ + + addis r3,r2,.byteswap_constant@toc@ha + addi r3,r3,.byteswap_constant@toc@l + + lvx byteswap,0,r3 + addi r3,r3,16 + + cmpdi r5,256 + blt .Lshort + + rldicr r6,r5,0,56 + + /* Checksum in blocks of MAX_SIZE */ +1: lis r7,MAX_SIZE@h + ori r7,r7,MAX_SIZE@l + mr r9,r7 + cmpd r6,r7 + bgt 2f + mr r7,r6 +2: subf r6,r7,r6 + + /* our main loop does 128 bytes at a time */ + srdi r7,r7,7 + + /* + * Work out the offset into the constants table to start at. Each + * constant is 16 bytes, and it is used against 128 bytes of input + * data - 128 / 16 = 8 + */ + sldi r8,r7,4 + srdi r9,r9,3 + subf r8,r8,r9 + + /* We reduce our final 128 bytes in a separate step */ + addi r7,r7,-1 + mtctr r7 + + addis r3,r2,CONSTANTS@toc@ha + addi r3,r3,CONSTANTS@toc@l + + /* Find the start of our constants */ + add r3,r3,r8 + + /* zero v0-v7 which will contain our checksums */ + vxor v0,v0,v0 + vxor v1,v1,v1 + vxor v2,v2,v2 + vxor v3,v3,v3 + vxor v4,v4,v4 + vxor v5,v5,v5 + vxor v6,v6,v6 + vxor v7,v7,v7 + + lvx const1,0,r3 + + /* + * If we are looping back to consume more data we use the values + * already in v16-v23. + */ + cmpdi r0,1 + beq 2f + + /* First warm up pass */ + lvx v16,0,r4 + lvx v17,off16,r4 + VPERM(v16,v16,v16,byteswap) + VPERM(v17,v17,v17,byteswap) + lvx v18,off32,r4 + lvx v19,off48,r4 + VPERM(v18,v18,v18,byteswap) + VPERM(v19,v19,v19,byteswap) + lvx v20,off64,r4 + lvx v21,off80,r4 + VPERM(v20,v20,v20,byteswap) + VPERM(v21,v21,v21,byteswap) + lvx v22,off96,r4 + lvx v23,off112,r4 + VPERM(v22,v22,v22,byteswap) + VPERM(v23,v23,v23,byteswap) + addi r4,r4,8*16 + + /* xor in initial value */ + vxor v16,v16,v8 + +2: bdz .Lfirst_warm_up_done + + addi r3,r3,16 + lvx const2,0,r3 + + /* Second warm up pass */ + VPMSUMD(v8,v16,const1) + lvx v16,0,r4 + VPERM(v16,v16,v16,byteswap) + ori r2,r2,0 + + VPMSUMD(v9,v17,const1) + lvx v17,off16,r4 + VPERM(v17,v17,v17,byteswap) + ori r2,r2,0 + + VPMSUMD(v10,v18,const1) + lvx v18,off32,r4 + VPERM(v18,v18,v18,byteswap) + ori r2,r2,0 + + VPMSUMD(v11,v19,const1) + lvx v19,off48,r4 + VPERM(v19,v19,v19,byteswap) + ori r2,r2,0 + + VPMSUMD(v12,v20,const1) + lvx v20,off64,r4 + VPERM(v20,v20,v20,byteswap) + ori r2,r2,0 + + VPMSUMD(v13,v21,const1) + lvx v21,off80,r4 + VPERM(v21,v21,v21,byteswap) + ori r2,r2,0 + + VPMSUMD(v14,v22,const1) + lvx v22,off96,r4 + VPERM(v22,v22,v22,byteswap) + ori r2,r2,0 + + VPMSUMD(v15,v23,const1) + lvx v23,off112,r4 + VPERM(v23,v23,v23,byteswap) + + addi r4,r4,8*16 + + bdz .Lfirst_cool_down + + /* + * main loop. We modulo schedule it such that it takes three iterations + * to complete - first iteration load, second iteration vpmsum, third + * iteration xor. + */ + .balign 16 +4: lvx const1,0,r3 + addi r3,r3,16 + ori r2,r2,0 + + vxor v0,v0,v8 + VPMSUMD(v8,v16,const2) + lvx v16,0,r4 + VPERM(v16,v16,v16,byteswap) + ori r2,r2,0 + + vxor v1,v1,v9 + VPMSUMD(v9,v17,const2) + lvx v17,off16,r4 + VPERM(v17,v17,v17,byteswap) + ori r2,r2,0 + + vxor v2,v2,v10 + VPMSUMD(v10,v18,const2) + lvx v18,off32,r4 + VPERM(v18,v18,v18,byteswap) + ori r2,r2,0 + + vxor v3,v3,v11 + VPMSUMD(v11,v19,const2) + lvx v19,off48,r4 + VPERM(v19,v19,v19,byteswap) + lvx const2,0,r3 + ori r2,r2,0 + + vxor v4,v4,v12 + VPMSUMD(v12,v20,const1) + lvx v20,off64,r4 + VPERM(v20,v20,v20,byteswap) + ori r2,r2,0 + + vxor v5,v5,v13 + VPMSUMD(v13,v21,const1) + lvx v21,off80,r4 + VPERM(v21,v21,v21,byteswap) + ori r2,r2,0 + + vxor v6,v6,v14 + VPMSUMD(v14,v22,const1) + lvx v22,off96,r4 + VPERM(v22,v22,v22,byteswap) + ori r2,r2,0 + + vxor v7,v7,v15 + VPMSUMD(v15,v23,const1) + lvx v23,off112,r4 + VPERM(v23,v23,v23,byteswap) + + addi r4,r4,8*16 + + bdnz 4b + +.Lfirst_cool_down: + /* First cool down pass */ + lvx const1,0,r3 + addi r3,r3,16 + + vxor v0,v0,v8 + VPMSUMD(v8,v16,const1) + ori r2,r2,0 + + vxor v1,v1,v9 + VPMSUMD(v9,v17,const1) + ori r2,r2,0 + + vxor v2,v2,v10 + VPMSUMD(v10,v18,const1) + ori r2,r2,0 + + vxor v3,v3,v11 + VPMSUMD(v11,v19,const1) + ori r2,r2,0 + + vxor v4,v4,v12 + VPMSUMD(v12,v20,const1) + ori r2,r2,0 + + vxor v5,v5,v13 + VPMSUMD(v13,v21,const1) + ori r2,r2,0 + + vxor v6,v6,v14 + VPMSUMD(v14,v22,const1) + ori r2,r2,0 + + vxor v7,v7,v15 + VPMSUMD(v15,v23,const1) + ori r2,r2,0 + +.Lsecond_cool_down: + /* Second cool down pass */ + vxor v0,v0,v8 + vxor v1,v1,v9 + vxor v2,v2,v10 + vxor v3,v3,v11 + vxor v4,v4,v12 + vxor v5,v5,v13 + vxor v6,v6,v14 + vxor v7,v7,v15 + + /* + * vpmsumd produces a 96 bit result in the least significant bits + * of the register. Since we are bit reflected we have to shift it + * left 32 bits so it occupies the least significant bits in the + * bit reflected domain. + */ + vsldoi v0,v0,zeroes,4 + vsldoi v1,v1,zeroes,4 + vsldoi v2,v2,zeroes,4 + vsldoi v3,v3,zeroes,4 + vsldoi v4,v4,zeroes,4 + vsldoi v5,v5,zeroes,4 + vsldoi v6,v6,zeroes,4 + vsldoi v7,v7,zeroes,4 + + /* xor with last 1024 bits */ + lvx v8,0,r4 + lvx v9,off16,r4 + VPERM(v8,v8,v8,byteswap) + VPERM(v9,v9,v9,byteswap) + lvx v10,off32,r4 + lvx v11,off48,r4 + VPERM(v10,v10,v10,byteswap) + VPERM(v11,v11,v11,byteswap) + lvx v12,off64,r4 + lvx v13,off80,r4 + VPERM(v12,v12,v12,byteswap) + VPERM(v13,v13,v13,byteswap) + lvx v14,off96,r4 + lvx v15,off112,r4 + VPERM(v14,v14,v14,byteswap) + VPERM(v15,v15,v15,byteswap) + + addi r4,r4,8*16 + + vxor v16,v0,v8 + vxor v17,v1,v9 + vxor v18,v2,v10 + vxor v19,v3,v11 + vxor v20,v4,v12 + vxor v21,v5,v13 + vxor v22,v6,v14 + vxor v23,v7,v15 + + li r0,1 + cmpdi r6,0 + addi r6,r6,128 + bne 1b + + /* Work out how many bytes we have left */ + andi. r5,r5,127 + + /* Calculate where in the constant table we need to start */ + subfic r6,r5,128 + add r3,r3,r6 + + /* How many 16 byte chunks are in the tail */ + srdi r7,r5,4 + mtctr r7 + + /* + * Reduce the previously calculated 1024 bits to 64 bits, shifting + * 32 bits to include the trailing 32 bits of zeros + */ + lvx v0,0,r3 + lvx v1,off16,r3 + lvx v2,off32,r3 + lvx v3,off48,r3 + lvx v4,off64,r3 + lvx v5,off80,r3 + lvx v6,off96,r3 + lvx v7,off112,r3 + addi r3,r3,8*16 + + VPMSUMW(v0,v16,v0) + VPMSUMW(v1,v17,v1) + VPMSUMW(v2,v18,v2) + VPMSUMW(v3,v19,v3) + VPMSUMW(v4,v20,v4) + VPMSUMW(v5,v21,v5) + VPMSUMW(v6,v22,v6) + VPMSUMW(v7,v23,v7) + + /* Now reduce the tail (0 - 112 bytes) */ + cmpdi r7,0 + beq 1f + + lvx v16,0,r4 + lvx v17,0,r3 + VPERM(v16,v16,v16,byteswap) + VPMSUMW(v16,v16,v17) + vxor v0,v0,v16 + bdz 1f + + lvx v16,off16,r4 + lvx v17,off16,r3 + VPERM(v16,v16,v16,byteswap) + VPMSUMW(v16,v16,v17) + vxor v0,v0,v16 + bdz 1f + + lvx v16,off32,r4 + lvx v17,off32,r3 + VPERM(v16,v16,v16,byteswap) + VPMSUMW(v16,v16,v17) + vxor v0,v0,v16 + bdz 1f + + lvx v16,off48,r4 + lvx v17,off48,r3 + VPERM(v16,v16,v16,byteswap) + VPMSUMW(v16,v16,v17) + vxor v0,v0,v16 + bdz 1f + + lvx v16,off64,r4 + lvx v17,off64,r3 + VPERM(v16,v16,v16,byteswap) + VPMSUMW(v16,v16,v17) + vxor v0,v0,v16 + bdz 1f + + lvx v16,off80,r4 + lvx v17,off80,r3 + VPERM(v16,v16,v16,byteswap) + VPMSUMW(v16,v16,v17) + vxor v0,v0,v16 + bdz 1f + + lvx v16,off96,r4 + lvx v17,off96,r3 + VPERM(v16,v16,v16,byteswap) + VPMSUMW(v16,v16,v17) + vxor v0,v0,v16 + + /* Now xor all the parallel chunks together */ +1: vxor v0,v0,v1 + vxor v2,v2,v3 + vxor v4,v4,v5 + vxor v6,v6,v7 + + vxor v0,v0,v2 + vxor v4,v4,v6 + + vxor v0,v0,v4 + +.Lbarrett_reduction: + /* Barrett constants */ + addis r3,r2,BARRETT_CONSTANTS@toc@ha + addi r3,r3,BARRETT_CONSTANTS@toc@l + + lvx const1,0,r3 + lvx const2,off16,r3 + + vsldoi v1,v0,v0,8 + vxor v0,v0,v1 /* xor two 64 bit results together */ + + /* shift left one bit */ + vspltisb v1,1 + vsl v0,v0,v1 + + vand v0,v0,mask_64bit + + /* + * The reflected version of Barrett reduction. Instead of bit + * reflecting our data (which is expensive to do), we bit reflect our + * constants and our algorithm, which means the intermediate data in + * our vector registers goes from 0-63 instead of 63-0. We can reflect + * the algorithm because we don't carry in mod 2 arithmetic. + */ + vand v1,v0,mask_32bit /* bottom 32 bits of a */ + VPMSUMD(v1,v1,const1) /* ma */ + vand v1,v1,mask_32bit /* bottom 32bits of ma */ + VPMSUMD(v1,v1,const2) /* qn */ + vxor v0,v0,v1 /* a - qn, subtraction is xor in GF(2) */ + + /* + * Since we are bit reflected, the result (ie the low 32 bits) is in + * the high 32 bits. We just need to shift it left 4 bytes + * V0 [ 0 1 X 3 ] + * V0 [ 0 X 2 3 ] + */ + vsldoi v0,v0,zeroes,4 /* shift result into top 64 bits of */ + +.Lout: + subi r6,r1,56+10*16 + subi r7,r1,56+2*16 + + lvx v20,0,r6 + lvx v21,off16,r6 + lvx v22,off32,r6 + lvx v23,off48,r6 + lvx v24,off64,r6 + lvx v25,off80,r6 + lvx v26,off96,r6 + lvx v27,off112,r6 + lvx v28,0,r7 + lvx v29,off16,r7 + + /* Get it into r3 */ + MFVRD(r3, v0) + + ld r31,-8(r1) + ld r30,-16(r1) + ld r29,-24(r1) + ld r28,-32(r1) + ld r27,-40(r1) + ld r26,-48(r1) + ld r25,-56(r1) + + blr + +.Lfirst_warm_up_done: + lvx const1,0,r3 + addi r3,r3,16 + + VPMSUMD(v8,v16,const1) + VPMSUMD(v9,v17,const1) + VPMSUMD(v10,v18,const1) + VPMSUMD(v11,v19,const1) + VPMSUMD(v12,v20,const1) + VPMSUMD(v13,v21,const1) + VPMSUMD(v14,v22,const1) + VPMSUMD(v15,v23,const1) + + b .Lsecond_cool_down + +.Lshort: + cmpdi r5,0 + beq .Lzero + + addis r3,r2,SHORT_CONSTANTS@toc@ha + addi r3,r3,SHORT_CONSTANTS@toc@l + + /* Calculate where in the constant table we need to start */ + subfic r6,r5,256 + add r3,r3,r6 + + /* How many 16 byte chunks? */ + srdi r7,r5,4 + mtctr r7 + + vxor v19,v19,v19 + vxor v20,v20,v20 + + lvx v0,0,r4 + lvx v16,0,r3 + VPERM(v0,v0,v16,byteswap) + vxor v0,v0,v8 /* xor in initial value */ + VPMSUMW(v0,v0,v16) + bdz .Lv0 + + lvx v1,off16,r4 + lvx v17,off16,r3 + VPERM(v1,v1,v17,byteswap) + VPMSUMW(v1,v1,v17) + bdz .Lv1 + + lvx v2,off32,r4 + lvx v16,off32,r3 + VPERM(v2,v2,v16,byteswap) + VPMSUMW(v2,v2,v16) + bdz .Lv2 + + lvx v3,off48,r4 + lvx v17,off48,r3 + VPERM(v3,v3,v17,byteswap) + VPMSUMW(v3,v3,v17) + bdz .Lv3 + + lvx v4,off64,r4 + lvx v16,off64,r3 + VPERM(v4,v4,v16,byteswap) + VPMSUMW(v4,v4,v16) + bdz .Lv4 + + lvx v5,off80,r4 + lvx v17,off80,r3 + VPERM(v5,v5,v17,byteswap) + VPMSUMW(v5,v5,v17) + bdz .Lv5 + + lvx v6,off96,r4 + lvx v16,off96,r3 + VPERM(v6,v6,v16,byteswap) + VPMSUMW(v6,v6,v16) + bdz .Lv6 + + lvx v7,off112,r4 + lvx v17,off112,r3 + VPERM(v7,v7,v17,byteswap) + VPMSUMW(v7,v7,v17) + bdz .Lv7 + + addi r3,r3,128 + addi r4,r4,128 + + lvx v8,0,r4 + lvx v16,0,r3 + VPERM(v8,v8,v16,byteswap) + VPMSUMW(v8,v8,v16) + bdz .Lv8 + + lvx v9,off16,r4 + lvx v17,off16,r3 + VPERM(v9,v9,v17,byteswap) + VPMSUMW(v9,v9,v17) + bdz .Lv9 + + lvx v10,off32,r4 + lvx v16,off32,r3 + VPERM(v10,v10,v16,byteswap) + VPMSUMW(v10,v10,v16) + bdz .Lv10 + + lvx v11,off48,r4 + lvx v17,off48,r3 + VPERM(v11,v11,v17,byteswap) + VPMSUMW(v11,v11,v17) + bdz .Lv11 + + lvx v12,off64,r4 + lvx v16,off64,r3 + VPERM(v12,v12,v16,byteswap) + VPMSUMW(v12,v12,v16) + bdz .Lv12 + + lvx v13,off80,r4 + lvx v17,off80,r3 + VPERM(v13,v13,v17,byteswap) + VPMSUMW(v13,v13,v17) + bdz .Lv13 + + lvx v14,off96,r4 + lvx v16,off96,r3 + VPERM(v14,v14,v16,byteswap) + VPMSUMW(v14,v14,v16) + bdz .Lv14 + + lvx v15,off112,r4 + lvx v17,off112,r3 + VPERM(v15,v15,v17,byteswap) + VPMSUMW(v15,v15,v17) + +.Lv15: vxor v19,v19,v15 +.Lv14: vxor v20,v20,v14 +.Lv13: vxor v19,v19,v13 +.Lv12: vxor v20,v20,v12 +.Lv11: vxor v19,v19,v11 +.Lv10: vxor v20,v20,v10 +.Lv9: vxor v19,v19,v9 +.Lv8: vxor v20,v20,v8 +.Lv7: vxor v19,v19,v7 +.Lv6: vxor v20,v20,v6 +.Lv5: vxor v19,v19,v5 +.Lv4: vxor v20,v20,v4 +.Lv3: vxor v19,v19,v3 +.Lv2: vxor v20,v20,v2 +.Lv1: vxor v19,v19,v1 +.Lv0: vxor v20,v20,v0 + + vxor v0,v19,v20 + + b .Lbarrett_reduction + +.Lzero: + mr r3,r10 + blr + b .Lout + +FUNC_END(__F) + +#endif /* __powerpc__ */ diff --git a/mysys/crc32_power8/crc32_constants.h b/mysys/crc32_power8/crc32_constants.h new file mode 100644 index 0000000..a99b1c0 --- /dev/null +++ b/mysys/crc32_power8/crc32_constants.h @@ -0,0 +1,835 @@ +#ifndef CRC32_CONSTANTS_H +#define CRC32_CONSTANTS_H + +#ifdef __powerpc__ + +#define MAX_SIZE 32768 +CONSTANTS: + + /* Reduce 262144 kbits to 1024 bits */ + /* x^261120 mod p(x)` << 1, x^261184 mod p(x)` << 1 */ + .octa 0x00000001651797d20000000099ea94a8 + + /* x^260096 mod p(x)` << 1, x^260160 mod p(x)` << 1 */ + .octa 0x0000000021e0d56c00000000945a8420 + + /* x^259072 mod p(x)` << 1, x^259136 mod p(x)` << 1 */ + .octa 0x000000000f95ecaa0000000030762706 + + /* x^258048 mod p(x)` << 1, x^258112 mod p(x)` << 1 */ + .octa 0x00000001ebd224ac00000001a52fc582 + + /* x^257024 mod p(x)` << 1, x^257088 mod p(x)` << 1 */ + .octa 0x000000000ccb97ca00000001a4a7167a + + /* x^256000 mod p(x)` << 1, x^256064 mod p(x)` << 1 */ + .octa 0x00000001006ec8a8000000000c18249a + + /* x^254976 mod p(x)` << 1, x^255040 mod p(x)` << 1 */ + .octa 0x000000014f58f19600000000a924ae7c + + /* x^253952 mod p(x)` << 1, x^254016 mod p(x)` << 1 */ + .octa 0x00000001a7192ca600000001e12ccc12 + + /* x^252928 mod p(x)` << 1, x^252992 mod p(x)` << 1 */ + .octa 0x000000019a64bab200000000a0b9d4ac + + /* x^251904 mod p(x)` << 1, x^251968 mod p(x)` << 1 */ + .octa 0x0000000014f4ed2e0000000095e8ddfe + + /* x^250880 mod p(x)` << 1, x^250944 mod p(x)` << 1 */ + .octa 0x000000011092b6a200000000233fddc4 + + /* x^249856 mod p(x)` << 1, x^249920 mod p(x)` << 1 */ + .octa 0x00000000c8a1629c00000001b4529b62 + + /* x^248832 mod p(x)` << 1, x^248896 mod p(x)` << 1 */ + .octa 0x000000017bf32e8e00000001a7fa0e64 + + /* x^247808 mod p(x)` << 1, x^247872 mod p(x)` << 1 */ + .octa 0x00000001f8cc658200000001b5334592 + + /* x^246784 mod p(x)` << 1, x^246848 mod p(x)` << 1 */ + .octa 0x000000008631ddf0000000011f8ee1b4 + + /* x^245760 mod p(x)` << 1, x^245824 mod p(x)` << 1 */ + .octa 0x000000007e5a76d0000000006252e632 + + /* x^244736 mod p(x)` << 1, x^244800 mod p(x)` << 1 */ + .octa 0x000000002b09b31c00000000ab973e84 + + /* x^243712 mod p(x)` << 1, x^243776 mod p(x)` << 1 */ + .octa 0x00000001b2df1f84000000007734f5ec + + /* x^242688 mod p(x)` << 1, x^242752 mod p(x)` << 1 */ + .octa 0x00000001d6f56afc000000007c547798 + + /* x^241664 mod p(x)` << 1, x^241728 mod p(x)` << 1 */ + .octa 0x00000001b9b5e70c000000007ec40210 + + /* x^240640 mod p(x)` << 1, x^240704 mod p(x)` << 1 */ + .octa 0x0000000034b626d200000001ab1695a8 + + /* x^239616 mod p(x)` << 1, x^239680 mod p(x)` << 1 */ + .octa 0x000000014c53479a0000000090494bba + + /* x^238592 mod p(x)` << 1, x^238656 mod p(x)` << 1 */ + .octa 0x00000001a6d179a400000001123fb816 + + /* x^237568 mod p(x)` << 1, x^237632 mod p(x)` << 1 */ + .octa 0x000000015abd16b400000001e188c74c + + /* x^236544 mod p(x)` << 1, x^236608 mod p(x)` << 1 */ + .octa 0x00000000018f985200000001c2d3451c + + /* x^235520 mod p(x)` << 1, x^235584 mod p(x)` << 1 */ + .octa 0x000000001fb3084a00000000f55cf1ca + + /* x^234496 mod p(x)` << 1, x^234560 mod p(x)` << 1 */ + .octa 0x00000000c53dfb0400000001a0531540 + + /* x^233472 mod p(x)` << 1, x^233536 mod p(x)` << 1 */ + .octa 0x00000000e10c9ad60000000132cd7ebc + + /* x^232448 mod p(x)` << 1, x^232512 mod p(x)` << 1 */ + .octa 0x0000000025aa994a0000000073ab7f36 + + /* x^231424 mod p(x)` << 1, x^231488 mod p(x)` << 1 */ + .octa 0x00000000fa3a74c40000000041aed1c2 + + /* x^230400 mod p(x)` << 1, x^230464 mod p(x)` << 1 */ + .octa 0x0000000033eb3f400000000136c53800 + + /* x^229376 mod p(x)` << 1, x^229440 mod p(x)` << 1 */ + .octa 0x000000017193f2960000000126835a30 + + /* x^228352 mod p(x)` << 1, x^228416 mod p(x)` << 1 */ + .octa 0x0000000043f6c86a000000006241b502 + + /* x^227328 mod p(x)` << 1, x^227392 mod p(x)` << 1 */ + .octa 0x000000016b513ec600000000d5196ad4 + + /* x^226304 mod p(x)` << 1, x^226368 mod p(x)` << 1 */ + .octa 0x00000000c8f25b4e000000009cfa769a + + /* x^225280 mod p(x)` << 1, x^225344 mod p(x)` << 1 */ + .octa 0x00000001a45048ec00000000920e5df4 + + /* x^224256 mod p(x)` << 1, x^224320 mod p(x)` << 1 */ + .octa 0x000000000c4410040000000169dc310e + + /* x^223232 mod p(x)` << 1, x^223296 mod p(x)` << 1 */ + .octa 0x000000000e17cad60000000009fc331c + + /* x^222208 mod p(x)` << 1, x^222272 mod p(x)` << 1 */ + .octa 0x00000001253ae964000000010d94a81e + + /* x^221184 mod p(x)` << 1, x^221248 mod p(x)` << 1 */ + .octa 0x00000001d7c88ebc0000000027a20ab2 + + /* x^220160 mod p(x)` << 1, x^220224 mod p(x)` << 1 */ + .octa 0x00000001e7ca913a0000000114f87504 + + /* x^219136 mod p(x)` << 1, x^219200 mod p(x)` << 1 */ + .octa 0x0000000033ed078a000000004b076d96 + + /* x^218112 mod p(x)` << 1, x^218176 mod p(x)` << 1 */ + .octa 0x00000000e1839c7800000000da4d1e74 + + /* x^217088 mod p(x)` << 1, x^217152 mod p(x)` << 1 */ + .octa 0x00000001322b267e000000001b81f672 + + /* x^216064 mod p(x)` << 1, x^216128 mod p(x)` << 1 */ + .octa 0x00000000638231b6000000009367c988 + + /* x^215040 mod p(x)` << 1, x^215104 mod p(x)` << 1 */ + .octa 0x00000001ee7f16f400000001717214ca + + /* x^214016 mod p(x)` << 1, x^214080 mod p(x)` << 1 */ + .octa 0x0000000117d9924a000000009f47d820 + + /* x^212992 mod p(x)` << 1, x^213056 mod p(x)` << 1 */ + .octa 0x00000000e1a9e0c4000000010d9a47d2 + + /* x^211968 mod p(x)` << 1, x^212032 mod p(x)` << 1 */ + .octa 0x00000001403731dc00000000a696c58c + + /* x^210944 mod p(x)` << 1, x^211008 mod p(x)` << 1 */ + .octa 0x00000001a5ea9682000000002aa28ec6 + + /* x^209920 mod p(x)` << 1, x^209984 mod p(x)` << 1 */ + .octa 0x0000000101c5c57800000001fe18fd9a + + /* x^208896 mod p(x)` << 1, x^208960 mod p(x)` << 1 */ + .octa 0x00000000dddf6494000000019d4fc1ae + + /* x^207872 mod p(x)` << 1, x^207936 mod p(x)` << 1 */ + .octa 0x00000000f1c3db2800000001ba0e3dea + + /* x^206848 mod p(x)` << 1, x^206912 mod p(x)` << 1 */ + .octa 0x000000013112fb9c0000000074b59a5e + + /* x^205824 mod p(x)` << 1, x^205888 mod p(x)` << 1 */ + .octa 0x00000000b680b90600000000f2b5ea98 + + /* x^204800 mod p(x)` << 1, x^204864 mod p(x)` << 1 */ + .octa 0x000000001a2829320000000187132676 + + /* x^203776 mod p(x)` << 1, x^203840 mod p(x)` << 1 */ + .octa 0x0000000089406e7e000000010a8c6ad4 + + /* x^202752 mod p(x)` << 1, x^202816 mod p(x)` << 1 */ + .octa 0x00000001def6be8c00000001e21dfe70 + + /* x^201728 mod p(x)` << 1, x^201792 mod p(x)` << 1 */ + .octa 0x000000007525872800000001da0050e4 + + /* x^200704 mod p(x)` << 1, x^200768 mod p(x)` << 1 */ + .octa 0x000000019536090a00000000772172ae + + /* x^199680 mod p(x)` << 1, x^199744 mod p(x)` << 1 */ + .octa 0x00000000f2455bfc00000000e47724aa + + /* x^198656 mod p(x)` << 1, x^198720 mod p(x)` << 1 */ + .octa 0x000000018c40baf4000000003cd63ac4 + + /* x^197632 mod p(x)` << 1, x^197696 mod p(x)` << 1 */ + .octa 0x000000004cd390d400000001bf47d352 + + /* x^196608 mod p(x)` << 1, x^196672 mod p(x)` << 1 */ + .octa 0x00000001e4ece95a000000018dc1d708 + + /* x^195584 mod p(x)` << 1, x^195648 mod p(x)` << 1 */ + .octa 0x000000001a3ee918000000002d4620a4 + + /* x^194560 mod p(x)` << 1, x^194624 mod p(x)` << 1 */ + .octa 0x000000007c652fb80000000058fd1740 + + /* x^193536 mod p(x)` << 1, x^193600 mod p(x)` << 1 */ + .octa 0x000000011c67842c00000000dadd9bfc + + /* x^192512 mod p(x)` << 1, x^192576 mod p(x)` << 1 */ + .octa 0x00000000254f759c00000001ea2140be + + /* x^191488 mod p(x)` << 1, x^191552 mod p(x)` << 1 */ + .octa 0x000000007ece94ca000000009de128ba + + /* x^190464 mod p(x)` << 1, x^190528 mod p(x)` << 1 */ + .octa 0x0000000038f258c2000000013ac3aa8e + + /* x^189440 mod p(x)` << 1, x^189504 mod p(x)` << 1 */ + .octa 0x00000001cdf17b000000000099980562 + + /* x^188416 mod p(x)` << 1, x^188480 mod p(x)` << 1 */ + .octa 0x000000011f882c1600000001c1579c86 + + /* x^187392 mod p(x)` << 1, x^187456 mod p(x)` << 1 */ + .octa 0x0000000100093fc80000000068dbbf94 + + /* x^186368 mod p(x)` << 1, x^186432 mod p(x)` << 1 */ + .octa 0x00000001cd684f16000000004509fb04 + + /* x^185344 mod p(x)` << 1, x^185408 mod p(x)` << 1 */ + .octa 0x000000004bc6a70a00000001202f6398 + + /* x^184320 mod p(x)` << 1, x^184384 mod p(x)` << 1 */ + .octa 0x000000004fc7e8e4000000013aea243e + + /* x^183296 mod p(x)` << 1, x^183360 mod p(x)` << 1 */ + .octa 0x0000000130103f1c00000001b4052ae6 + + /* x^182272 mod p(x)` << 1, x^182336 mod p(x)` << 1 */ + .octa 0x0000000111b0024c00000001cd2a0ae8 + + /* x^181248 mod p(x)` << 1, x^181312 mod p(x)` << 1 */ + .octa 0x000000010b3079da00000001fe4aa8b4 + + /* x^180224 mod p(x)` << 1, x^180288 mod p(x)` << 1 */ + .octa 0x000000010192bcc200000001d1559a42 + + /* x^179200 mod p(x)` << 1, x^179264 mod p(x)` << 1 */ + .octa 0x0000000074838d5000000001f3e05ecc + + /* x^178176 mod p(x)` << 1, x^178240 mod p(x)` << 1 */ + .octa 0x000000001b20f5200000000104ddd2cc + + /* x^177152 mod p(x)` << 1, x^177216 mod p(x)` << 1 */ + .octa 0x0000000050c3590a000000015393153c + + /* x^176128 mod p(x)` << 1, x^176192 mod p(x)` << 1 */ + .octa 0x00000000b41cac8e0000000057e942c6 + + /* x^175104 mod p(x)` << 1, x^175168 mod p(x)` << 1 */ + .octa 0x000000000c72cc78000000012c633850 + + /* x^174080 mod p(x)` << 1, x^174144 mod p(x)` << 1 */ + .octa 0x0000000030cdb03200000000ebcaae4c + + /* x^173056 mod p(x)` << 1, x^173120 mod p(x)` << 1 */ + .octa 0x000000013e09fc32000000013ee532a6 + + /* x^172032 mod p(x)` << 1, x^172096 mod p(x)` << 1 */ + .octa 0x000000001ed624d200000001bf0cbc7e + + /* x^171008 mod p(x)` << 1, x^171072 mod p(x)` << 1 */ + .octa 0x00000000781aee1a00000000d50b7a5a + + /* x^169984 mod p(x)` << 1, x^170048 mod p(x)` << 1 */ + .octa 0x00000001c4d8348c0000000002fca6e8 + + /* x^168960 mod p(x)` << 1, x^169024 mod p(x)` << 1 */ + .octa 0x0000000057a40336000000007af40044 + + /* x^167936 mod p(x)` << 1, x^168000 mod p(x)` << 1 */ + .octa 0x00000000855449400000000016178744 + + /* x^166912 mod p(x)` << 1, x^166976 mod p(x)` << 1 */ + .octa 0x000000019cd21e80000000014c177458 + + /* x^165888 mod p(x)` << 1, x^165952 mod p(x)` << 1 */ + .octa 0x000000013eb95bc0000000011b6ddf04 + + /* x^164864 mod p(x)` << 1, x^164928 mod p(x)` << 1 */ + .octa 0x00000001dfc9fdfc00000001f3e29ccc + + /* x^163840 mod p(x)` << 1, x^163904 mod p(x)` << 1 */ + .octa 0x00000000cd028bc20000000135ae7562 + + /* x^162816 mod p(x)` << 1, x^162880 mod p(x)` << 1 */ + .octa 0x0000000090db8c440000000190ef812c + + /* x^161792 mod p(x)` << 1, x^161856 mod p(x)` << 1 */ + .octa 0x000000010010a4ce0000000067a2c786 + + /* x^160768 mod p(x)` << 1, x^160832 mod p(x)` << 1 */ + .octa 0x00000001c8f4c72c0000000048b9496c + + /* x^159744 mod p(x)` << 1, x^159808 mod p(x)` << 1 */ + .octa 0x000000001c26170c000000015a422de6 + + /* x^158720 mod p(x)` << 1, x^158784 mod p(x)` << 1 */ + .octa 0x00000000e3fccf6800000001ef0e3640 + + /* x^157696 mod p(x)` << 1, x^157760 mod p(x)` << 1 */ + .octa 0x00000000d513ed2400000001006d2d26 + + /* x^156672 mod p(x)` << 1, x^156736 mod p(x)` << 1 */ + .octa 0x00000000141beada00000001170d56d6 + + /* x^155648 mod p(x)` << 1, x^155712 mod p(x)` << 1 */ + .octa 0x000000011071aea000000000a5fb613c + + /* x^154624 mod p(x)` << 1, x^154688 mod p(x)` << 1 */ + .octa 0x000000012e19080a0000000040bbf7fc + + /* x^153600 mod p(x)` << 1, x^153664 mod p(x)` << 1 */ + .octa 0x0000000100ecf826000000016ac3a5b2 + + /* x^152576 mod p(x)` << 1, x^152640 mod p(x)` << 1 */ + .octa 0x0000000069b0941200000000abf16230 + + /* x^151552 mod p(x)` << 1, x^151616 mod p(x)` << 1 */ + .octa 0x0000000122297bac00000001ebe23fac + + /* x^150528 mod p(x)` << 1, x^150592 mod p(x)` << 1 */ + .octa 0x00000000e9e4b068000000008b6a0894 + + /* x^149504 mod p(x)` << 1, x^149568 mod p(x)` << 1 */ + .octa 0x000000004b38651a00000001288ea478 + + /* x^148480 mod p(x)` << 1, x^148544 mod p(x)` << 1 */ + .octa 0x00000001468360e2000000016619c442 + + /* x^147456 mod p(x)` << 1, x^147520 mod p(x)` << 1 */ + .octa 0x00000000121c24080000000086230038 + + /* x^146432 mod p(x)` << 1, x^146496 mod p(x)` << 1 */ + .octa 0x00000000da7e7d08000000017746a756 + + /* x^145408 mod p(x)` << 1, x^145472 mod p(x)` << 1 */ + .octa 0x00000001058d76520000000191b8f8f8 + + /* x^144384 mod p(x)` << 1, x^144448 mod p(x)` << 1 */ + .octa 0x000000014a098a90000000008e167708 + + /* x^143360 mod p(x)` << 1, x^143424 mod p(x)` << 1 */ + .octa 0x0000000020dbe72e0000000148b22d54 + + /* x^142336 mod p(x)` << 1, x^142400 mod p(x)` << 1 */ + .octa 0x000000011e7323e80000000044ba2c3c + + /* x^141312 mod p(x)` << 1, x^141376 mod p(x)` << 1 */ + .octa 0x00000000d5d4bf9400000000b54d2b52 + + /* x^140288 mod p(x)` << 1, x^140352 mod p(x)` << 1 */ + .octa 0x0000000199d8746c0000000005a4fd8a + + /* x^139264 mod p(x)` << 1, x^139328 mod p(x)` << 1 */ + .octa 0x00000000ce9ca8a00000000139f9fc46 + + /* x^138240 mod p(x)` << 1, x^138304 mod p(x)` << 1 */ + .octa 0x00000000136edece000000015a1fa824 + + /* x^137216 mod p(x)` << 1, x^137280 mod p(x)` << 1 */ + .octa 0x000000019b92a068000000000a61ae4c + + /* x^136192 mod p(x)` << 1, x^136256 mod p(x)` << 1 */ + .octa 0x0000000071d622060000000145e9113e + + /* x^135168 mod p(x)` << 1, x^135232 mod p(x)` << 1 */ + .octa 0x00000000dfc50158000000006a348448 + + /* x^134144 mod p(x)` << 1, x^134208 mod p(x)` << 1 */ + .octa 0x00000001517626bc000000004d80a08c + + /* x^133120 mod p(x)` << 1, x^133184 mod p(x)` << 1 */ + .octa 0x0000000148d1e4fa000000014b6837a0 + + /* x^132096 mod p(x)` << 1, x^132160 mod p(x)` << 1 */ + .octa 0x0000000094d8266e000000016896a7fc + + /* x^131072 mod p(x)` << 1, x^131136 mod p(x)` << 1 */ + .octa 0x00000000606c5e34000000014f187140 + + /* x^130048 mod p(x)` << 1, x^130112 mod p(x)` << 1 */ + .octa 0x000000019766beaa000000019581b9da + + /* x^129024 mod p(x)` << 1, x^129088 mod p(x)` << 1 */ + .octa 0x00000001d80c506c00000001091bc984 + + /* x^128000 mod p(x)` << 1, x^128064 mod p(x)` << 1 */ + .octa 0x000000001e73837c000000001067223c + + /* x^126976 mod p(x)` << 1, x^127040 mod p(x)` << 1 */ + .octa 0x0000000064d587de00000001ab16ea02 + + /* x^125952 mod p(x)` << 1, x^126016 mod p(x)` << 1 */ + .octa 0x00000000f4a507b0000000013c4598a8 + + /* x^124928 mod p(x)` << 1, x^124992 mod p(x)` << 1 */ + .octa 0x0000000040e342fc00000000b3735430 + + /* x^123904 mod p(x)` << 1, x^123968 mod p(x)` << 1 */ + .octa 0x00000001d5ad9c3a00000001bb3fc0c0 + + /* x^122880 mod p(x)` << 1, x^122944 mod p(x)` << 1 */ + .octa 0x0000000094a691a400000001570ae19c + + /* x^121856 mod p(x)` << 1, x^121920 mod p(x)` << 1 */ + .octa 0x00000001271ecdfa00000001ea910712 + + /* x^120832 mod p(x)` << 1, x^120896 mod p(x)` << 1 */ + .octa 0x000000009e54475a0000000167127128 + + /* x^119808 mod p(x)` << 1, x^119872 mod p(x)` << 1 */ + .octa 0x00000000c9c099ee0000000019e790a2 + + /* x^118784 mod p(x)` << 1, x^118848 mod p(x)` << 1 */ + .octa 0x000000009a2f736c000000003788f710 + + /* x^117760 mod p(x)` << 1, x^117824 mod p(x)` << 1 */ + .octa 0x00000000bb9f499600000001682a160e + + /* x^116736 mod p(x)` << 1, x^116800 mod p(x)` << 1 */ + .octa 0x00000001db688050000000007f0ebd2e + + /* x^115712 mod p(x)` << 1, x^115776 mod p(x)` << 1 */ + .octa 0x00000000e9b10af4000000002b032080 + + /* x^114688 mod p(x)` << 1, x^114752 mod p(x)` << 1 */ + .octa 0x000000012d4545e400000000cfd1664a + + /* x^113664 mod p(x)` << 1, x^113728 mod p(x)` << 1 */ + .octa 0x000000000361139c00000000aa1181c2 + + /* x^112640 mod p(x)` << 1, x^112704 mod p(x)` << 1 */ + .octa 0x00000001a5a1a3a800000000ddd08002 + + /* x^111616 mod p(x)` << 1, x^111680 mod p(x)` << 1 */ + .octa 0x000000006844e0b000000000e8dd0446 + + /* x^110592 mod p(x)` << 1, x^110656 mod p(x)` << 1 */ + .octa 0x00000000c3762f2800000001bbd94a00 + + /* x^109568 mod p(x)` << 1, x^109632 mod p(x)` << 1 */ + .octa 0x00000001d26287a200000000ab6cd180 + + /* x^108544 mod p(x)` << 1, x^108608 mod p(x)` << 1 */ + .octa 0x00000001f6f0bba80000000031803ce2 + + /* x^107520 mod p(x)` << 1, x^107584 mod p(x)` << 1 */ + .octa 0x000000002ffabd620000000024f40b0c + + /* x^106496 mod p(x)` << 1, x^106560 mod p(x)` << 1 */ + .octa 0x00000000fb4516b800000001ba1d9834 + + /* x^105472 mod p(x)` << 1, x^105536 mod p(x)` << 1 */ + .octa 0x000000018cfa961c0000000104de61aa + + /* x^104448 mod p(x)` << 1, x^104512 mod p(x)` << 1 */ + .octa 0x000000019e588d520000000113e40d46 + + /* x^103424 mod p(x)` << 1, x^103488 mod p(x)` << 1 */ + .octa 0x00000001180f0bbc00000001415598a0 + + /* x^102400 mod p(x)` << 1, x^102464 mod p(x)` << 1 */ + .octa 0x00000000e1d9177a00000000bf6c8c90 + + /* x^101376 mod p(x)` << 1, x^101440 mod p(x)` << 1 */ + .octa 0x0000000105abc27c00000001788b0504 + + /* x^100352 mod p(x)` << 1, x^100416 mod p(x)` << 1 */ + .octa 0x00000000972e4a580000000038385d02 + + /* x^99328 mod p(x)` << 1, x^99392 mod p(x)` << 1 */ + .octa 0x0000000183499a5e00000001b6c83844 + + /* x^98304 mod p(x)` << 1, x^98368 mod p(x)` << 1 */ + .octa 0x00000001c96a8cca0000000051061a8a + + /* x^97280 mod p(x)` << 1, x^97344 mod p(x)` << 1 */ + .octa 0x00000001a1a5b60c000000017351388a + + /* x^96256 mod p(x)` << 1, x^96320 mod p(x)` << 1 */ + .octa 0x00000000e4b6ac9c0000000132928f92 + + /* x^95232 mod p(x)` << 1, x^95296 mod p(x)` << 1 */ + .octa 0x00000001807e7f5a00000000e6b4f48a + + /* x^94208 mod p(x)` << 1, x^94272 mod p(x)` << 1 */ + .octa 0x000000017a7e3bc80000000039d15e90 + + /* x^93184 mod p(x)` << 1, x^93248 mod p(x)` << 1 */ + .octa 0x00000000d73975da00000000312d6074 + + /* x^92160 mod p(x)` << 1, x^92224 mod p(x)` << 1 */ + .octa 0x000000017375d038000000017bbb2cc4 + + /* x^91136 mod p(x)` << 1, x^91200 mod p(x)` << 1 */ + .octa 0x00000000193680bc000000016ded3e18 + + /* x^90112 mod p(x)` << 1, x^90176 mod p(x)` << 1 */ + .octa 0x00000000999b06f600000000f1638b16 + + /* x^89088 mod p(x)` << 1, x^89152 mod p(x)` << 1 */ + .octa 0x00000001f685d2b800000001d38b9ecc + + /* x^88064 mod p(x)` << 1, x^88128 mod p(x)` << 1 */ + .octa 0x00000001f4ecbed2000000018b8d09dc + + /* x^87040 mod p(x)` << 1, x^87104 mod p(x)` << 1 */ + .octa 0x00000000ba16f1a000000000e7bc27d2 + + /* x^86016 mod p(x)` << 1, x^86080 mod p(x)` << 1 */ + .octa 0x0000000115aceac400000000275e1e96 + + /* x^84992 mod p(x)` << 1, x^85056 mod p(x)` << 1 */ + .octa 0x00000001aeff629200000000e2e3031e + + /* x^83968 mod p(x)` << 1, x^84032 mod p(x)` << 1 */ + .octa 0x000000009640124c00000001041c84d8 + + /* x^82944 mod p(x)` << 1, x^83008 mod p(x)` << 1 */ + .octa 0x0000000114f41f0200000000706ce672 + + /* x^81920 mod p(x)` << 1, x^81984 mod p(x)` << 1 */ + .octa 0x000000009c5f3586000000015d5070da + + /* x^80896 mod p(x)` << 1, x^80960 mod p(x)` << 1 */ + .octa 0x00000001878275fa0000000038f9493a + + /* x^79872 mod p(x)` << 1, x^79936 mod p(x)` << 1 */ + .octa 0x00000000ddc42ce800000000a3348a76 + + /* x^78848 mod p(x)` << 1, x^78912 mod p(x)` << 1 */ + .octa 0x0000000181d2c73a00000001ad0aab92 + + /* x^77824 mod p(x)` << 1, x^77888 mod p(x)` << 1 */ + .octa 0x0000000141c9320a000000019e85f712 + + /* x^76800 mod p(x)` << 1, x^76864 mod p(x)` << 1 */ + .octa 0x000000015235719a000000005a871e76 + + /* x^75776 mod p(x)` << 1, x^75840 mod p(x)` << 1 */ + .octa 0x00000000be27d804000000017249c662 + + /* x^74752 mod p(x)` << 1, x^74816 mod p(x)` << 1 */ + .octa 0x000000006242d45a000000003a084712 + + /* x^73728 mod p(x)` << 1, x^73792 mod p(x)` << 1 */ + .octa 0x000000009a53638e00000000ed438478 + + /* x^72704 mod p(x)` << 1, x^72768 mod p(x)` << 1 */ + .octa 0x00000001001ecfb600000000abac34cc + + /* x^71680 mod p(x)` << 1, x^71744 mod p(x)` << 1 */ + .octa 0x000000016d7c2d64000000005f35ef3e + + /* x^70656 mod p(x)` << 1, x^70720 mod p(x)` << 1 */ + .octa 0x00000001d0ce46c00000000047d6608c + + /* x^69632 mod p(x)` << 1, x^69696 mod p(x)` << 1 */ + .octa 0x0000000124c907b4000000002d01470e + + /* x^68608 mod p(x)` << 1, x^68672 mod p(x)` << 1 */ + .octa 0x0000000018a555ca0000000158bbc7b0 + + /* x^67584 mod p(x)` << 1, x^67648 mod p(x)` << 1 */ + .octa 0x000000006b0980bc00000000c0a23e8e + + /* x^66560 mod p(x)` << 1, x^66624 mod p(x)` << 1 */ + .octa 0x000000008bbba96400000001ebd85c88 + + /* x^65536 mod p(x)` << 1, x^65600 mod p(x)` << 1 */ + .octa 0x00000001070a5a1e000000019ee20bb2 + + /* x^64512 mod p(x)` << 1, x^64576 mod p(x)` << 1 */ + .octa 0x000000002204322a00000001acabf2d6 + + /* x^63488 mod p(x)` << 1, x^63552 mod p(x)` << 1 */ + .octa 0x00000000a27524d000000001b7963d56 + + /* x^62464 mod p(x)` << 1, x^62528 mod p(x)` << 1 */ + .octa 0x0000000020b1e4ba000000017bffa1fe + + /* x^61440 mod p(x)` << 1, x^61504 mod p(x)` << 1 */ + .octa 0x0000000032cc27fc000000001f15333e + + /* x^60416 mod p(x)` << 1, x^60480 mod p(x)` << 1 */ + .octa 0x0000000044dd22b8000000018593129e + + /* x^59392 mod p(x)` << 1, x^59456 mod p(x)` << 1 */ + .octa 0x00000000dffc9e0a000000019cb32602 + + /* x^58368 mod p(x)` << 1, x^58432 mod p(x)` << 1 */ + .octa 0x00000001b7a0ed140000000142b05cc8 + + /* x^57344 mod p(x)` << 1, x^57408 mod p(x)` << 1 */ + .octa 0x00000000c784248800000001be49e7a4 + + /* x^56320 mod p(x)` << 1, x^56384 mod p(x)` << 1 */ + .octa 0x00000001c02a4fee0000000108f69d6c + + /* x^55296 mod p(x)` << 1, x^55360 mod p(x)` << 1 */ + .octa 0x000000003c273778000000006c0971f0 + + /* x^54272 mod p(x)` << 1, x^54336 mod p(x)` << 1 */ + .octa 0x00000001d63f8894000000005b16467a + + /* x^53248 mod p(x)` << 1, x^53312 mod p(x)` << 1 */ + .octa 0x000000006be557d600000001551a628e + + /* x^52224 mod p(x)` << 1, x^52288 mod p(x)` << 1 */ + .octa 0x000000006a7806ea000000019e42ea92 + + /* x^51200 mod p(x)` << 1, x^51264 mod p(x)` << 1 */ + .octa 0x000000016155aa0c000000012fa83ff2 + + /* x^50176 mod p(x)` << 1, x^50240 mod p(x)` << 1 */ + .octa 0x00000000908650ac000000011ca9cde0 + + /* x^49152 mod p(x)` << 1, x^49216 mod p(x)` << 1 */ + .octa 0x00000000aa5a808400000000c8e5cd74 + + /* x^48128 mod p(x)` << 1, x^48192 mod p(x)` << 1 */ + .octa 0x0000000191bb500a0000000096c27f0c + + /* x^47104 mod p(x)` << 1, x^47168 mod p(x)` << 1 */ + .octa 0x0000000064e9bed0000000002baed926 + + /* x^46080 mod p(x)` << 1, x^46144 mod p(x)` << 1 */ + .octa 0x000000009444f302000000017c8de8d2 + + /* x^45056 mod p(x)` << 1, x^45120 mod p(x)` << 1 */ + .octa 0x000000019db07d3c00000000d43d6068 + + /* x^44032 mod p(x)` << 1, x^44096 mod p(x)` << 1 */ + .octa 0x00000001359e3e6e00000000cb2c4b26 + + /* x^43008 mod p(x)` << 1, x^43072 mod p(x)` << 1 */ + .octa 0x00000001e4f10dd20000000145b8da26 + + /* x^41984 mod p(x)` << 1, x^42048 mod p(x)` << 1 */ + .octa 0x0000000124f5735e000000018fff4b08 + + /* x^40960 mod p(x)` << 1, x^41024 mod p(x)` << 1 */ + .octa 0x0000000124760a4c0000000150b58ed0 + + /* x^39936 mod p(x)` << 1, x^40000 mod p(x)` << 1 */ + .octa 0x000000000f1fc18600000001549f39bc + + /* x^38912 mod p(x)` << 1, x^38976 mod p(x)` << 1 */ + .octa 0x00000000150e4cc400000000ef4d2f42 + + /* x^37888 mod p(x)` << 1, x^37952 mod p(x)` << 1 */ + .octa 0x000000002a6204e800000001b1468572 + + /* x^36864 mod p(x)` << 1, x^36928 mod p(x)` << 1 */ + .octa 0x00000000beb1d432000000013d7403b2 + + /* x^35840 mod p(x)` << 1, x^35904 mod p(x)` << 1 */ + .octa 0x0000000135f3f1f000000001a4681842 + + /* x^34816 mod p(x)` << 1, x^34880 mod p(x)` << 1 */ + .octa 0x0000000074fe22320000000167714492 + + /* x^33792 mod p(x)` << 1, x^33856 mod p(x)` << 1 */ + .octa 0x000000001ac6e2ba00000001e599099a + + /* x^32768 mod p(x)` << 1, x^32832 mod p(x)` << 1 */ + .octa 0x0000000013fca91e00000000fe128194 + + /* x^31744 mod p(x)` << 1, x^31808 mod p(x)` << 1 */ + .octa 0x0000000183f4931e0000000077e8b990 + + /* x^30720 mod p(x)` << 1, x^30784 mod p(x)` << 1 */ + .octa 0x00000000b6d9b4e400000001a267f63a + + /* x^29696 mod p(x)` << 1, x^29760 mod p(x)` << 1 */ + .octa 0x00000000b518865600000001945c245a + + /* x^28672 mod p(x)` << 1, x^28736 mod p(x)` << 1 */ + .octa 0x0000000027a81a840000000149002e76 + + /* x^27648 mod p(x)` << 1, x^27712 mod p(x)` << 1 */ + .octa 0x000000012569925800000001bb8310a4 + + /* x^26624 mod p(x)` << 1, x^26688 mod p(x)` << 1 */ + .octa 0x00000001b23de796000000019ec60bcc + + /* x^25600 mod p(x)` << 1, x^25664 mod p(x)` << 1 */ + .octa 0x00000000fe4365dc000000012d8590ae + + /* x^24576 mod p(x)` << 1, x^24640 mod p(x)` << 1 */ + .octa 0x00000000c68f497a0000000065b00684 + + /* x^23552 mod p(x)` << 1, x^23616 mod p(x)` << 1 */ + .octa 0x00000000fbf521ee000000015e5aeadc + + /* x^22528 mod p(x)` << 1, x^22592 mod p(x)` << 1 */ + .octa 0x000000015eac337800000000b77ff2b0 + + /* x^21504 mod p(x)` << 1, x^21568 mod p(x)` << 1 */ + .octa 0x0000000134914b900000000188da2ff6 + + /* x^20480 mod p(x)` << 1, x^20544 mod p(x)` << 1 */ + .octa 0x0000000016335cfe0000000063da929a + + /* x^19456 mod p(x)` << 1, x^19520 mod p(x)` << 1 */ + .octa 0x000000010372d10c00000001389caa80 + + /* x^18432 mod p(x)` << 1, x^18496 mod p(x)` << 1 */ + .octa 0x000000015097b908000000013db599d2 + + /* x^17408 mod p(x)` << 1, x^17472 mod p(x)` << 1 */ + .octa 0x00000001227a75720000000122505a86 + + /* x^16384 mod p(x)` << 1, x^16448 mod p(x)` << 1 */ + .octa 0x000000009a8f75c0000000016bd72746 + + /* x^15360 mod p(x)` << 1, x^15424 mod p(x)` << 1 */ + .octa 0x00000000682c77a200000001c3faf1d4 + + /* x^14336 mod p(x)` << 1, x^14400 mod p(x)` << 1 */ + .octa 0x00000000231f091c00000001111c826c + + /* x^13312 mod p(x)` << 1, x^13376 mod p(x)` << 1 */ + .octa 0x000000007d4439f200000000153e9fb2 + + /* x^12288 mod p(x)` << 1, x^12352 mod p(x)` << 1 */ + .octa 0x000000017e221efc000000002b1f7b60 + + /* x^11264 mod p(x)` << 1, x^11328 mod p(x)` << 1 */ + .octa 0x0000000167457c3800000000b1dba570 + + /* x^10240 mod p(x)` << 1, x^10304 mod p(x)` << 1 */ + .octa 0x00000000bdf081c400000001f6397b76 + + /* x^9216 mod p(x)` << 1, x^9280 mod p(x)` << 1 */ + .octa 0x000000016286d6b00000000156335214 + + /* x^8192 mod p(x)` << 1, x^8256 mod p(x)` << 1 */ + .octa 0x00000000c84f001c00000001d70e3986 + + /* x^7168 mod p(x)` << 1, x^7232 mod p(x)` << 1 */ + .octa 0x0000000064efe7c0000000003701a774 + + /* x^6144 mod p(x)` << 1, x^6208 mod p(x)` << 1 */ + .octa 0x000000000ac2d90400000000ac81ef72 + + /* x^5120 mod p(x)` << 1, x^5184 mod p(x)` << 1 */ + .octa 0x00000000fd226d140000000133212464 + + /* x^4096 mod p(x)` << 1, x^4160 mod p(x)` << 1 */ + .octa 0x000000011cfd42e000000000e4e45610 + + /* x^3072 mod p(x)` << 1, x^3136 mod p(x)` << 1 */ + .octa 0x000000016e5a5678000000000c1bd370 + + /* x^2048 mod p(x)` << 1, x^2112 mod p(x)` << 1 */ + .octa 0x00000001d888fe2200000001a7b9e7a6 + + /* x^1024 mod p(x)` << 1, x^1088 mod p(x)` << 1 */ + .octa 0x00000001af77fcd4000000007d657a10 + +SHORT_CONSTANTS: + + /* Reduce final 1024-2048 bits to 64 bits, shifting 32 bits to include the trailing 32 bits of zeros */ + /* x^1952 mod p(x)`, x^1984 mod p(x)`, x^2016 mod p(x)`, x^2048 mod p(x)` */ + .octa 0xed837b2613e8221e99168a18ec447f11 + + /* x^1824 mod p(x)`, x^1856 mod p(x)`, x^1888 mod p(x)`, x^1920 mod p(x)` */ + .octa 0xc8acdd8147b9ce5ae23e954e8fd2cd3c + + /* x^1696 mod p(x)`, x^1728 mod p(x)`, x^1760 mod p(x)`, x^1792 mod p(x)` */ + .octa 0xd9ad6d87d4277e2592f8befe6b1d2b53 + + /* x^1568 mod p(x)`, x^1600 mod p(x)`, x^1632 mod p(x)`, x^1664 mod p(x)` */ + .octa 0xc10ec5e033fbca3bf38a3556291ea462 + + /* x^1440 mod p(x)`, x^1472 mod p(x)`, x^1504 mod p(x)`, x^1536 mod p(x)` */ + .octa 0xc0b55b0e82e02e2f974ac56262b6ca4b + + /* x^1312 mod p(x)`, x^1344 mod p(x)`, x^1376 mod p(x)`, x^1408 mod p(x)` */ + .octa 0x71aa1df0e172334d855712b3784d2a56 + + /* x^1184 mod p(x)`, x^1216 mod p(x)`, x^1248 mod p(x)`, x^1280 mod p(x)` */ + .octa 0xfee3053e3969324da5abe9f80eaee722 + + /* x^1056 mod p(x)`, x^1088 mod p(x)`, x^1120 mod p(x)`, x^1152 mod p(x)` */ + .octa 0xf44779b93eb2bd081fa0943ddb54814c + + /* x^928 mod p(x)`, x^960 mod p(x)`, x^992 mod p(x)`, x^1024 mod p(x)` */ + .octa 0xf5449b3f00cc3374a53ff440d7bbfe6a + + /* x^800 mod p(x)`, x^832 mod p(x)`, x^864 mod p(x)`, x^896 mod p(x)` */ + .octa 0x6f8346e1d777606eebe7e3566325605c + + /* x^672 mod p(x)`, x^704 mod p(x)`, x^736 mod p(x)`, x^768 mod p(x)` */ + .octa 0xe3ab4f2ac0b95347c65a272ce5b592b8 + + /* x^544 mod p(x)`, x^576 mod p(x)`, x^608 mod p(x)`, x^640 mod p(x)` */ + .octa 0xaa2215ea329ecc115705a9ca4721589f + + /* x^416 mod p(x)`, x^448 mod p(x)`, x^480 mod p(x)`, x^512 mod p(x)` */ + .octa 0x1ed8f66ed95efd26e3720acb88d14467 + + /* x^288 mod p(x)`, x^320 mod p(x)`, x^352 mod p(x)`, x^384 mod p(x)` */ + .octa 0x78ed02d5a700e96aba1aca0315141c31 + + /* x^160 mod p(x)`, x^192 mod p(x)`, x^224 mod p(x)`, x^256 mod p(x)` */ + .octa 0xba8ccbe832b39da3ad2a31b3ed627dae + + /* x^32 mod p(x)`, x^64 mod p(x)`, x^96 mod p(x)`, x^128 mod p(x)` */ + .octa 0xedb88320b1e6b0926655004fa06a2517 + + +BARRETT_CONSTANTS: + /* 33 bit reflected Barrett constant m - (4^32)/n */ + .octa 0x000000000000000000000001f7011641 /* x^64 div p(x)` */ + /* 33 bit reflected Barrett constant n */ + .octa 0x000000000000000000000001db710641 + +#endif /* __powerpc__ */ + +#endif diff --git a/mysys/crc32_power8/crc32_wrapper.c b/mysys/crc32_power8/crc32_wrapper.c new file mode 100644 index 0000000..b153099 --- /dev/null +++ b/mysys/crc32_power8/crc32_wrapper.c @@ -0,0 +1,75 @@ +#ifdef __powerpc__ + +#define F crc32_vpmsum +#define __F __crc32_vpmsum + +static const unsigned int crc_table[] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,}; + +#include "crc32_wrapper.ic" + +#endif + diff --git a/mysys/crc32_power8/crc32_wrapper.ic b/mysys/crc32_power8/crc32_wrapper.ic new file mode 100644 index 0000000..750e971 --- /dev/null +++ b/mysys/crc32_power8/crc32_wrapper.ic @@ -0,0 +1,52 @@ +#ifdef __powerpc__ + + +#define VMX_ALIGN 16 +#define VMX_ALIGN_MASK (VMX_ALIGN-1) + +static unsigned int crc32_align(unsigned int crc, unsigned char *p, + unsigned long len) +{ + while (len--) + crc = crc_table[(crc ^ *p++) & 0xff] ^ (crc >> 8); + return crc; +} + +unsigned int __F(unsigned int crc, unsigned char *p, + unsigned long len); + +unsigned int F(unsigned int crc, unsigned char *p, + unsigned long len) +{ + unsigned int prealign; + unsigned int tail; + + crc ^= 0xffffffff; + + if (len < VMX_ALIGN + VMX_ALIGN_MASK) { + crc = crc32_align(crc, p, len); + goto out; + } + + if ((unsigned long)p & VMX_ALIGN_MASK) { + prealign = VMX_ALIGN - ((unsigned long)p & VMX_ALIGN_MASK); + crc = crc32_align(crc, p, prealign); + len -= prealign; + p += prealign; + } + + crc = __F(crc, p, len & ~VMX_ALIGN_MASK); + + tail = len & VMX_ALIGN_MASK; + if (tail) { + p += len & ~VMX_ALIGN_MASK; + crc = crc32_align(crc, p, tail); + } + +out: + crc ^= 0xffffffff; + + return crc; +} + +#endif /* __powerpc__ */ diff --git a/mysys/crc32_power8/crc32c.S b/mysys/crc32_power8/crc32c.S new file mode 100644 index 0000000..390c4bf --- /dev/null +++ b/mysys/crc32_power8/crc32c.S @@ -0,0 +1,14 @@ +#ifdef __powerpc__ + +#define CONSTANTS .crc32c_constants +#define SHORT_CONSTANTS .crc32c_short_constants +#define BARRETT_CONSTANTS .crc32c_barrett_constants + +#include "crc32c_constants.h" + +#define __F __crc32c_vpmsum + +#include "crc32.iS" + +#endif + diff --git a/mysys/crc32_power8/crc32c_constants.h b/mysys/crc32_power8/crc32c_constants.h new file mode 100644 index 0000000..555b785 --- /dev/null +++ b/mysys/crc32_power8/crc32c_constants.h @@ -0,0 +1,837 @@ +#ifndef CRC32_CONSTANTS_H +#define CRC32_CONSTANTS_H + +#ifdef __powerpc__ + +#define CRC 0x1edc6f41 + +#define MAX_SIZE 32768 +CONSTANTS: + + /* Reduce 262144 kbits to 1024 bits */ + /* x^261120 mod p(x)` << 1, x^261184 mod p(x)` << 1 */ + .octa 0x00000000b6ca9e20000000009c37c408 + + /* x^260096 mod p(x)` << 1, x^260160 mod p(x)` << 1 */ + .octa 0x00000000350249a800000001b51df26c + + /* x^259072 mod p(x)` << 1, x^259136 mod p(x)` << 1 */ + .octa 0x00000001862dac54000000000724b9d0 + + /* x^258048 mod p(x)` << 1, x^258112 mod p(x)` << 1 */ + .octa 0x00000001d87fb48c00000001c00532fe + + /* x^257024 mod p(x)` << 1, x^257088 mod p(x)` << 1 */ + .octa 0x00000001f39b699e00000000f05a9362 + + /* x^256000 mod p(x)` << 1, x^256064 mod p(x)` << 1 */ + .octa 0x0000000101da11b400000001e1007970 + + /* x^254976 mod p(x)` << 1, x^255040 mod p(x)` << 1 */ + .octa 0x00000001cab571e000000000a57366ee + + /* x^253952 mod p(x)` << 1, x^254016 mod p(x)` << 1 */ + .octa 0x00000000c7020cfe0000000192011284 + + /* x^252928 mod p(x)` << 1, x^252992 mod p(x)` << 1 */ + .octa 0x00000000cdaed1ae0000000162716d9a + + /* x^251904 mod p(x)` << 1, x^251968 mod p(x)` << 1 */ + .octa 0x00000001e804effc00000000cd97ecde + + /* x^250880 mod p(x)` << 1, x^250944 mod p(x)` << 1 */ + .octa 0x0000000077c3ea3a0000000058812bc0 + + /* x^249856 mod p(x)` << 1, x^249920 mod p(x)` << 1 */ + .octa 0x0000000068df31b40000000088b8c12e + + /* x^248832 mod p(x)` << 1, x^248896 mod p(x)` << 1 */ + .octa 0x00000000b059b6c200000001230b234c + + /* x^247808 mod p(x)` << 1, x^247872 mod p(x)` << 1 */ + .octa 0x0000000145fb8ed800000001120b416e + + /* x^246784 mod p(x)` << 1, x^246848 mod p(x)` << 1 */ + .octa 0x00000000cbc0916800000001974aecb0 + + /* x^245760 mod p(x)` << 1, x^245824 mod p(x)` << 1 */ + .octa 0x000000005ceeedc2000000008ee3f226 + + /* x^244736 mod p(x)` << 1, x^244800 mod p(x)` << 1 */ + .octa 0x0000000047d74e8600000001089aba9a + + /* x^243712 mod p(x)` << 1, x^243776 mod p(x)` << 1 */ + .octa 0x00000001407e9e220000000065113872 + + /* x^242688 mod p(x)` << 1, x^242752 mod p(x)` << 1 */ + .octa 0x00000001da967bda000000005c07ec10 + + /* x^241664 mod p(x)` << 1, x^241728 mod p(x)` << 1 */ + .octa 0x000000006c8983680000000187590924 + + /* x^240640 mod p(x)` << 1, x^240704 mod p(x)` << 1 */ + .octa 0x00000000f2d14c9800000000e35da7c6 + + /* x^239616 mod p(x)` << 1, x^239680 mod p(x)` << 1 */ + .octa 0x00000001993c6ad4000000000415855a + + /* x^238592 mod p(x)` << 1, x^238656 mod p(x)` << 1 */ + .octa 0x000000014683d1ac0000000073617758 + + /* x^237568 mod p(x)` << 1, x^237632 mod p(x)` << 1 */ + .octa 0x00000001a7c93e6c0000000176021d28 + + /* x^236544 mod p(x)` << 1, x^236608 mod p(x)` << 1 */ + .octa 0x000000010211e90a00000001c358fd0a + + /* x^235520 mod p(x)` << 1, x^235584 mod p(x)` << 1 */ + .octa 0x000000001119403e00000001ff7a2c18 + + /* x^234496 mod p(x)` << 1, x^234560 mod p(x)` << 1 */ + .octa 0x000000001c3261aa00000000f2d9f7e4 + + /* x^233472 mod p(x)` << 1, x^233536 mod p(x)` << 1 */ + .octa 0x000000014e37a634000000016cf1f9c8 + + /* x^232448 mod p(x)` << 1, x^232512 mod p(x)` << 1 */ + .octa 0x0000000073786c0c000000010af9279a + + /* x^231424 mod p(x)` << 1, x^231488 mod p(x)` << 1 */ + .octa 0x000000011dc037f80000000004f101e8 + + /* x^230400 mod p(x)` << 1, x^230464 mod p(x)` << 1 */ + .octa 0x0000000031433dfc0000000070bcf184 + + /* x^229376 mod p(x)` << 1, x^229440 mod p(x)` << 1 */ + .octa 0x000000009cde8348000000000a8de642 + + /* x^228352 mod p(x)` << 1, x^228416 mod p(x)` << 1 */ + .octa 0x0000000038d3c2a60000000062ea130c + + /* x^227328 mod p(x)` << 1, x^227392 mod p(x)` << 1 */ + .octa 0x000000011b25f26000000001eb31cbb2 + + /* x^226304 mod p(x)` << 1, x^226368 mod p(x)` << 1 */ + .octa 0x000000001629e6f00000000170783448 + + /* x^225280 mod p(x)` << 1, x^225344 mod p(x)` << 1 */ + .octa 0x0000000160838b4c00000001a684b4c6 + + /* x^224256 mod p(x)` << 1, x^224320 mod p(x)` << 1 */ + .octa 0x000000007a44011c00000000253ca5b4 + + /* x^223232 mod p(x)` << 1, x^223296 mod p(x)` << 1 */ + .octa 0x00000000226f417a0000000057b4b1e2 + + /* x^222208 mod p(x)` << 1, x^222272 mod p(x)` << 1 */ + .octa 0x0000000045eb2eb400000000b6bd084c + + /* x^221184 mod p(x)` << 1, x^221248 mod p(x)` << 1 */ + .octa 0x000000014459d70c0000000123c2d592 + + /* x^220160 mod p(x)` << 1, x^220224 mod p(x)` << 1 */ + .octa 0x00000001d406ed8200000000159dafce + + /* x^219136 mod p(x)` << 1, x^219200 mod p(x)` << 1 */ + .octa 0x0000000160c8e1a80000000127e1a64e + + /* x^218112 mod p(x)` << 1, x^218176 mod p(x)` << 1 */ + .octa 0x0000000027ba80980000000056860754 + + /* x^217088 mod p(x)` << 1, x^217152 mod p(x)` << 1 */ + .octa 0x000000006d92d01800000001e661aae8 + + /* x^216064 mod p(x)` << 1, x^216128 mod p(x)` << 1 */ + .octa 0x000000012ed7e3f200000000f82c6166 + + /* x^215040 mod p(x)` << 1, x^215104 mod p(x)` << 1 */ + .octa 0x000000002dc8778800000000c4f9c7ae + + /* x^214016 mod p(x)` << 1, x^214080 mod p(x)` << 1 */ + .octa 0x0000000018240bb80000000074203d20 + + /* x^212992 mod p(x)` << 1, x^213056 mod p(x)` << 1 */ + .octa 0x000000001ad381580000000198173052 + + /* x^211968 mod p(x)` << 1, x^212032 mod p(x)` << 1 */ + .octa 0x00000001396b78f200000001ce8aba54 + + /* x^210944 mod p(x)` << 1, x^211008 mod p(x)` << 1 */ + .octa 0x000000011a68133400000001850d5d94 + + /* x^209920 mod p(x)` << 1, x^209984 mod p(x)` << 1 */ + .octa 0x000000012104732e00000001d609239c + + /* x^208896 mod p(x)` << 1, x^208960 mod p(x)` << 1 */ + .octa 0x00000000a140d90c000000001595f048 + + /* x^207872 mod p(x)` << 1, x^207936 mod p(x)` << 1 */ + .octa 0x00000001b7215eda0000000042ccee08 + + /* x^206848 mod p(x)` << 1, x^206912 mod p(x)` << 1 */ + .octa 0x00000001aaf1df3c000000010a389d74 + + /* x^205824 mod p(x)` << 1, x^205888 mod p(x)` << 1 */ + .octa 0x0000000029d15b8a000000012a840da6 + + /* x^204800 mod p(x)` << 1, x^204864 mod p(x)` << 1 */ + .octa 0x00000000f1a96922000000001d181c0c + + /* x^203776 mod p(x)` << 1, x^203840 mod p(x)` << 1 */ + .octa 0x00000001ac80d03c0000000068b7d1f6 + + /* x^202752 mod p(x)` << 1, x^202816 mod p(x)` << 1 */ + .octa 0x000000000f11d56a000000005b0f14fc + + /* x^201728 mod p(x)` << 1, x^201792 mod p(x)` << 1 */ + .octa 0x00000001f1c022a20000000179e9e730 + + /* x^200704 mod p(x)` << 1, x^200768 mod p(x)` << 1 */ + .octa 0x0000000173d00ae200000001ce1368d6 + + /* x^199680 mod p(x)` << 1, x^199744 mod p(x)` << 1 */ + .octa 0x00000001d4ffe4ac0000000112c3a84c + + /* x^198656 mod p(x)` << 1, x^198720 mod p(x)` << 1 */ + .octa 0x000000016edc5ae400000000de940fee + + /* x^197632 mod p(x)` << 1, x^197696 mod p(x)` << 1 */ + .octa 0x00000001f1a0214000000000fe896b7e + + /* x^196608 mod p(x)` << 1, x^196672 mod p(x)` << 1 */ + .octa 0x00000000ca0b28a000000001f797431c + + /* x^195584 mod p(x)` << 1, x^195648 mod p(x)` << 1 */ + .octa 0x00000001928e30a20000000053e989ba + + /* x^194560 mod p(x)` << 1, x^194624 mod p(x)` << 1 */ + .octa 0x0000000097b1b002000000003920cd16 + + /* x^193536 mod p(x)` << 1, x^193600 mod p(x)` << 1 */ + .octa 0x00000000b15bf90600000001e6f579b8 + + /* x^192512 mod p(x)` << 1, x^192576 mod p(x)` << 1 */ + .octa 0x00000000411c5d52000000007493cb0a + + /* x^191488 mod p(x)` << 1, x^191552 mod p(x)` << 1 */ + .octa 0x00000001c36f330000000001bdd376d8 + + /* x^190464 mod p(x)` << 1, x^190528 mod p(x)` << 1 */ + .octa 0x00000001119227e0000000016badfee6 + + /* x^189440 mod p(x)` << 1, x^189504 mod p(x)` << 1 */ + .octa 0x00000000114d47020000000071de5c58 + + /* x^188416 mod p(x)` << 1, x^188480 mod p(x)` << 1 */ + .octa 0x00000000458b5b9800000000453f317c + + /* x^187392 mod p(x)` << 1, x^187456 mod p(x)` << 1 */ + .octa 0x000000012e31fb8e0000000121675cce + + /* x^186368 mod p(x)` << 1, x^186432 mod p(x)` << 1 */ + .octa 0x000000005cf619d800000001f409ee92 + + /* x^185344 mod p(x)` << 1, x^185408 mod p(x)` << 1 */ + .octa 0x0000000063f4d8b200000000f36b9c88 + + /* x^184320 mod p(x)` << 1, x^184384 mod p(x)` << 1 */ + .octa 0x000000004138dc8a0000000036b398f4 + + /* x^183296 mod p(x)` << 1, x^183360 mod p(x)` << 1 */ + .octa 0x00000001d29ee8e000000001748f9adc + + /* x^182272 mod p(x)` << 1, x^182336 mod p(x)` << 1 */ + .octa 0x000000006a08ace800000001be94ec00 + + /* x^181248 mod p(x)` << 1, x^181312 mod p(x)` << 1 */ + .octa 0x0000000127d4201000000000b74370d6 + + /* x^180224 mod p(x)` << 1, x^180288 mod p(x)` << 1 */ + .octa 0x0000000019d76b6200000001174d0b98 + + /* x^179200 mod p(x)` << 1, x^179264 mod p(x)` << 1 */ + .octa 0x00000001b1471f6e00000000befc06a4 + + /* x^178176 mod p(x)` << 1, x^178240 mod p(x)` << 1 */ + .octa 0x00000001f64c19cc00000001ae125288 + + /* x^177152 mod p(x)` << 1, x^177216 mod p(x)` << 1 */ + .octa 0x00000000003c0ea00000000095c19b34 + + /* x^176128 mod p(x)` << 1, x^176192 mod p(x)` << 1 */ + .octa 0x000000014d73abf600000001a78496f2 + + /* x^175104 mod p(x)` << 1, x^175168 mod p(x)` << 1 */ + .octa 0x00000001620eb84400000001ac5390a0 + + /* x^174080 mod p(x)` << 1, x^174144 mod p(x)` << 1 */ + .octa 0x0000000147655048000000002a80ed6e + + /* x^173056 mod p(x)` << 1, x^173120 mod p(x)` << 1 */ + .octa 0x0000000067b5077e00000001fa9b0128 + + /* x^172032 mod p(x)` << 1, x^172096 mod p(x)` << 1 */ + .octa 0x0000000010ffe20600000001ea94929e + + /* x^171008 mod p(x)` << 1, x^171072 mod p(x)` << 1 */ + .octa 0x000000000fee8f1e0000000125f4305c + + /* x^169984 mod p(x)` << 1, x^170048 mod p(x)` << 1 */ + .octa 0x00000001da26fbae00000001471e2002 + + /* x^168960 mod p(x)` << 1, x^169024 mod p(x)` << 1 */ + .octa 0x00000001b3a8bd880000000132d2253a + + /* x^167936 mod p(x)` << 1, x^168000 mod p(x)` << 1 */ + .octa 0x00000000e8f3898e00000000f26b3592 + + /* x^166912 mod p(x)` << 1, x^166976 mod p(x)` << 1 */ + .octa 0x00000000b0d0d28c00000000bc8b67b0 + + /* x^165888 mod p(x)` << 1, x^165952 mod p(x)` << 1 */ + .octa 0x0000000030f2a798000000013a826ef2 + + /* x^164864 mod p(x)` << 1, x^164928 mod p(x)` << 1 */ + .octa 0x000000000fba10020000000081482c84 + + /* x^163840 mod p(x)` << 1, x^163904 mod p(x)` << 1 */ + .octa 0x00000000bdb9bd7200000000e77307c2 + + /* x^162816 mod p(x)` << 1, x^162880 mod p(x)` << 1 */ + .octa 0x0000000075d3bf5a00000000d4a07ec8 + + /* x^161792 mod p(x)` << 1, x^161856 mod p(x)` << 1 */ + .octa 0x00000000ef1f98a00000000017102100 + + /* x^160768 mod p(x)` << 1, x^160832 mod p(x)` << 1 */ + .octa 0x00000000689c760200000000db406486 + + /* x^159744 mod p(x)` << 1, x^159808 mod p(x)` << 1 */ + .octa 0x000000016d5fa5fe0000000192db7f88 + + /* x^158720 mod p(x)` << 1, x^158784 mod p(x)` << 1 */ + .octa 0x00000001d0d2b9ca000000018bf67b1e + + /* x^157696 mod p(x)` << 1, x^157760 mod p(x)` << 1 */ + .octa 0x0000000041e7b470000000007c09163e + + /* x^156672 mod p(x)` << 1, x^156736 mod p(x)` << 1 */ + .octa 0x00000001cbb6495e000000000adac060 + + /* x^155648 mod p(x)` << 1, x^155712 mod p(x)` << 1 */ + .octa 0x000000010052a0b000000000bd8316ae + + /* x^154624 mod p(x)` << 1, x^154688 mod p(x)` << 1 */ + .octa 0x00000001d8effb5c000000019f09ab54 + + /* x^153600 mod p(x)` << 1, x^153664 mod p(x)` << 1 */ + .octa 0x00000001d969853c0000000125155542 + + /* x^152576 mod p(x)` << 1, x^152640 mod p(x)` << 1 */ + .octa 0x00000000523ccce2000000018fdb5882 + + /* x^151552 mod p(x)` << 1, x^151616 mod p(x)` << 1 */ + .octa 0x000000001e2436bc00000000e794b3f4 + + /* x^150528 mod p(x)` << 1, x^150592 mod p(x)` << 1 */ + .octa 0x00000000ddd1c3a2000000016f9bb022 + + /* x^149504 mod p(x)` << 1, x^149568 mod p(x)` << 1 */ + .octa 0x0000000019fcfe3800000000290c9978 + + /* x^148480 mod p(x)` << 1, x^148544 mod p(x)` << 1 */ + .octa 0x00000001ce95db640000000083c0f350 + + /* x^147456 mod p(x)` << 1, x^147520 mod p(x)` << 1 */ + .octa 0x00000000af5828060000000173ea6628 + + /* x^146432 mod p(x)` << 1, x^146496 mod p(x)` << 1 */ + .octa 0x00000001006388f600000001c8b4e00a + + /* x^145408 mod p(x)` << 1, x^145472 mod p(x)` << 1 */ + .octa 0x0000000179eca00a00000000de95d6aa + + /* x^144384 mod p(x)` << 1, x^144448 mod p(x)` << 1 */ + .octa 0x0000000122410a6a000000010b7f7248 + + /* x^143360 mod p(x)` << 1, x^143424 mod p(x)` << 1 */ + .octa 0x000000004288e87c00000001326e3a06 + + /* x^142336 mod p(x)` << 1, x^142400 mod p(x)` << 1 */ + .octa 0x000000016c5490da00000000bb62c2e6 + + /* x^141312 mod p(x)` << 1, x^141376 mod p(x)` << 1 */ + .octa 0x00000000d1c71f6e0000000156a4b2c2 + + /* x^140288 mod p(x)` << 1, x^140352 mod p(x)` << 1 */ + .octa 0x00000001b4ce08a6000000011dfe763a + + /* x^139264 mod p(x)` << 1, x^139328 mod p(x)` << 1 */ + .octa 0x00000001466ba60c000000007bcca8e2 + + /* x^138240 mod p(x)` << 1, x^138304 mod p(x)` << 1 */ + .octa 0x00000001f6c488a40000000186118faa + + /* x^137216 mod p(x)` << 1, x^137280 mod p(x)` << 1 */ + .octa 0x000000013bfb06820000000111a65a88 + + /* x^136192 mod p(x)` << 1, x^136256 mod p(x)` << 1 */ + .octa 0x00000000690e9e54000000003565e1c4 + + /* x^135168 mod p(x)` << 1, x^135232 mod p(x)` << 1 */ + .octa 0x00000000281346b6000000012ed02a82 + + /* x^134144 mod p(x)` << 1, x^134208 mod p(x)` << 1 */ + .octa 0x000000015646402400000000c486ecfc + + /* x^133120 mod p(x)` << 1, x^133184 mod p(x)` << 1 */ + .octa 0x000000016063a8dc0000000001b951b2 + + /* x^132096 mod p(x)` << 1, x^132160 mod p(x)` << 1 */ + .octa 0x0000000116a663620000000048143916 + + /* x^131072 mod p(x)` << 1, x^131136 mod p(x)` << 1 */ + .octa 0x000000017e8aa4d200000001dc2ae124 + + /* x^130048 mod p(x)` << 1, x^130112 mod p(x)` << 1 */ + .octa 0x00000001728eb10c00000001416c58d6 + + /* x^129024 mod p(x)` << 1, x^129088 mod p(x)` << 1 */ + .octa 0x00000001b08fd7fa00000000a479744a + + /* x^128000 mod p(x)` << 1, x^128064 mod p(x)` << 1 */ + .octa 0x00000001092a16e80000000096ca3a26 + + /* x^126976 mod p(x)` << 1, x^127040 mod p(x)` << 1 */ + .octa 0x00000000a505637c00000000ff223d4e + + /* x^125952 mod p(x)` << 1, x^126016 mod p(x)` << 1 */ + .octa 0x00000000d94869b2000000010e84da42 + + /* x^124928 mod p(x)` << 1, x^124992 mod p(x)` << 1 */ + .octa 0x00000001c8b203ae00000001b61ba3d0 + + /* x^123904 mod p(x)` << 1, x^123968 mod p(x)` << 1 */ + .octa 0x000000005704aea000000000680f2de8 + + /* x^122880 mod p(x)` << 1, x^122944 mod p(x)` << 1 */ + .octa 0x000000012e295fa2000000008772a9a8 + + /* x^121856 mod p(x)` << 1, x^121920 mod p(x)` << 1 */ + .octa 0x000000011d0908bc0000000155f295bc + + /* x^120832 mod p(x)` << 1, x^120896 mod p(x)` << 1 */ + .octa 0x0000000193ed97ea00000000595f9282 + + /* x^119808 mod p(x)` << 1, x^119872 mod p(x)` << 1 */ + .octa 0x000000013a0f1c520000000164b1c25a + + /* x^118784 mod p(x)` << 1, x^118848 mod p(x)` << 1 */ + .octa 0x000000010c2c40c000000000fbd67c50 + + /* x^117760 mod p(x)` << 1, x^117824 mod p(x)` << 1 */ + .octa 0x00000000ff6fac3e0000000096076268 + + /* x^116736 mod p(x)` << 1, x^116800 mod p(x)` << 1 */ + .octa 0x000000017b3609c000000001d288e4cc + + /* x^115712 mod p(x)` << 1, x^115776 mod p(x)` << 1 */ + .octa 0x0000000088c8c92200000001eaac1bdc + + /* x^114688 mod p(x)` << 1, x^114752 mod p(x)` << 1 */ + .octa 0x00000001751baae600000001f1ea39e2 + + /* x^113664 mod p(x)` << 1, x^113728 mod p(x)` << 1 */ + .octa 0x000000010795297200000001eb6506fc + + /* x^112640 mod p(x)` << 1, x^112704 mod p(x)` << 1 */ + .octa 0x0000000162b00abe000000010f806ffe + + /* x^111616 mod p(x)` << 1, x^111680 mod p(x)` << 1 */ + .octa 0x000000000d7b404c000000010408481e + + /* x^110592 mod p(x)` << 1, x^110656 mod p(x)` << 1 */ + .octa 0x00000000763b13d40000000188260534 + + /* x^109568 mod p(x)` << 1, x^109632 mod p(x)` << 1 */ + .octa 0x00000000f6dc22d80000000058fc73e0 + + /* x^108544 mod p(x)` << 1, x^108608 mod p(x)` << 1 */ + .octa 0x000000007daae06000000000391c59b8 + + /* x^107520 mod p(x)` << 1, x^107584 mod p(x)` << 1 */ + .octa 0x000000013359ab7c000000018b638400 + + /* x^106496 mod p(x)` << 1, x^106560 mod p(x)` << 1 */ + .octa 0x000000008add438a000000011738f5c4 + + /* x^105472 mod p(x)` << 1, x^105536 mod p(x)` << 1 */ + .octa 0x00000001edbefdea000000008cf7c6da + + /* x^104448 mod p(x)` << 1, x^104512 mod p(x)` << 1 */ + .octa 0x000000004104e0f800000001ef97fb16 + + /* x^103424 mod p(x)` << 1, x^103488 mod p(x)` << 1 */ + .octa 0x00000000b48a82220000000102130e20 + + /* x^102400 mod p(x)` << 1, x^102464 mod p(x)` << 1 */ + .octa 0x00000001bcb4684400000000db968898 + + /* x^101376 mod p(x)` << 1, x^101440 mod p(x)` << 1 */ + .octa 0x000000013293ce0a00000000b5047b5e + + /* x^100352 mod p(x)` << 1, x^100416 mod p(x)` << 1 */ + .octa 0x00000001710d0844000000010b90fdb2 + + /* x^99328 mod p(x)` << 1, x^99392 mod p(x)` << 1 */ + .octa 0x0000000117907f6e000000004834a32e + + /* x^98304 mod p(x)` << 1, x^98368 mod p(x)` << 1 */ + .octa 0x0000000087ddf93e0000000059c8f2b0 + + /* x^97280 mod p(x)` << 1, x^97344 mod p(x)` << 1 */ + .octa 0x000000005970e9b00000000122cec508 + + /* x^96256 mod p(x)` << 1, x^96320 mod p(x)` << 1 */ + .octa 0x0000000185b2b7d0000000000a330cda + + /* x^95232 mod p(x)` << 1, x^95296 mod p(x)` << 1 */ + .octa 0x00000001dcee0efc000000014a47148c + + /* x^94208 mod p(x)` << 1, x^94272 mod p(x)` << 1 */ + .octa 0x0000000030da27220000000042c61cb8 + + /* x^93184 mod p(x)` << 1, x^93248 mod p(x)` << 1 */ + .octa 0x000000012f925a180000000012fe6960 + + /* x^92160 mod p(x)` << 1, x^92224 mod p(x)` << 1 */ + .octa 0x00000000dd2e357c00000000dbda2c20 + + /* x^91136 mod p(x)` << 1, x^91200 mod p(x)` << 1 */ + .octa 0x00000000071c80de000000011122410c + + /* x^90112 mod p(x)` << 1, x^90176 mod p(x)` << 1 */ + .octa 0x000000011513140a00000000977b2070 + + /* x^89088 mod p(x)` << 1, x^89152 mod p(x)` << 1 */ + .octa 0x00000001df876e8e000000014050438e + + /* x^88064 mod p(x)` << 1, x^88128 mod p(x)` << 1 */ + .octa 0x000000015f81d6ce0000000147c840e8 + + /* x^87040 mod p(x)` << 1, x^87104 mod p(x)` << 1 */ + .octa 0x000000019dd94dbe00000001cc7c88ce + + /* x^86016 mod p(x)` << 1, x^86080 mod p(x)` << 1 */ + .octa 0x00000001373d206e00000001476b35a4 + + /* x^84992 mod p(x)` << 1, x^85056 mod p(x)` << 1 */ + .octa 0x00000000668ccade000000013d52d508 + + /* x^83968 mod p(x)` << 1, x^84032 mod p(x)` << 1 */ + .octa 0x00000001b192d268000000008e4be32e + + /* x^82944 mod p(x)` << 1, x^83008 mod p(x)` << 1 */ + .octa 0x00000000e30f3a7800000000024120fe + + /* x^81920 mod p(x)` << 1, x^81984 mod p(x)` << 1 */ + .octa 0x000000010ef1f7bc00000000ddecddb4 + + /* x^80896 mod p(x)` << 1, x^80960 mod p(x)` << 1 */ + .octa 0x00000001f5ac738000000000d4d403bc + + /* x^79872 mod p(x)` << 1, x^79936 mod p(x)` << 1 */ + .octa 0x000000011822ea7000000001734b89aa + + /* x^78848 mod p(x)` << 1, x^78912 mod p(x)` << 1 */ + .octa 0x00000000c3a33848000000010e7a58d6 + + /* x^77824 mod p(x)` << 1, x^77888 mod p(x)` << 1 */ + .octa 0x00000001bd151c2400000001f9f04e9c + + /* x^76800 mod p(x)` << 1, x^76864 mod p(x)` << 1 */ + .octa 0x0000000056002d7600000000b692225e + + /* x^75776 mod p(x)` << 1, x^75840 mod p(x)` << 1 */ + .octa 0x000000014657c4f4000000019b8d3f3e + + /* x^74752 mod p(x)` << 1, x^74816 mod p(x)` << 1 */ + .octa 0x0000000113742d7c00000001a874f11e + + /* x^73728 mod p(x)` << 1, x^73792 mod p(x)` << 1 */ + .octa 0x000000019c5920ba000000010d5a4254 + + /* x^72704 mod p(x)` << 1, x^72768 mod p(x)` << 1 */ + .octa 0x000000005216d2d600000000bbb2f5d6 + + /* x^71680 mod p(x)` << 1, x^71744 mod p(x)` << 1 */ + .octa 0x0000000136f5ad8a0000000179cc0e36 + + /* x^70656 mod p(x)` << 1, x^70720 mod p(x)` << 1 */ + .octa 0x000000018b07beb600000001dca1da4a + + /* x^69632 mod p(x)` << 1, x^69696 mod p(x)` << 1 */ + .octa 0x00000000db1e93b000000000feb1a192 + + /* x^68608 mod p(x)` << 1, x^68672 mod p(x)` << 1 */ + .octa 0x000000000b96fa3a00000000d1eeedd6 + + /* x^67584 mod p(x)` << 1, x^67648 mod p(x)` << 1 */ + .octa 0x00000001d9968af0000000008fad9bb4 + + /* x^66560 mod p(x)` << 1, x^66624 mod p(x)` << 1 */ + .octa 0x000000000e4a77a200000001884938e4 + + /* x^65536 mod p(x)` << 1, x^65600 mod p(x)` << 1 */ + .octa 0x00000000508c2ac800000001bc2e9bc0 + + /* x^64512 mod p(x)` << 1, x^64576 mod p(x)` << 1 */ + .octa 0x0000000021572a8000000001f9658a68 + + /* x^63488 mod p(x)` << 1, x^63552 mod p(x)` << 1 */ + .octa 0x00000001b859daf2000000001b9224fc + + /* x^62464 mod p(x)` << 1, x^62528 mod p(x)` << 1 */ + .octa 0x000000016f7884740000000055b2fb84 + + /* x^61440 mod p(x)` << 1, x^61504 mod p(x)` << 1 */ + .octa 0x00000001b438810e000000018b090348 + + /* x^60416 mod p(x)` << 1, x^60480 mod p(x)` << 1 */ + .octa 0x0000000095ddc6f2000000011ccbd5ea + + /* x^59392 mod p(x)` << 1, x^59456 mod p(x)` << 1 */ + .octa 0x00000001d977c20c0000000007ae47f8 + + /* x^58368 mod p(x)` << 1, x^58432 mod p(x)` << 1 */ + .octa 0x00000000ebedb99a0000000172acbec0 + + /* x^57344 mod p(x)` << 1, x^57408 mod p(x)` << 1 */ + .octa 0x00000001df9e9e9200000001c6e3ff20 + + /* x^56320 mod p(x)` << 1, x^56384 mod p(x)` << 1 */ + .octa 0x00000001a4a3f95200000000e1b38744 + + /* x^55296 mod p(x)` << 1, x^55360 mod p(x)` << 1 */ + .octa 0x00000000e2f5122000000000791585b2 + + /* x^54272 mod p(x)` << 1, x^54336 mod p(x)` << 1 */ + .octa 0x000000004aa01f3e00000000ac53b894 + + /* x^53248 mod p(x)` << 1, x^53312 mod p(x)` << 1 */ + .octa 0x00000000b3e90a5800000001ed5f2cf4 + + /* x^52224 mod p(x)` << 1, x^52288 mod p(x)` << 1 */ + .octa 0x000000000c9ca2aa00000001df48b2e0 + + /* x^51200 mod p(x)` << 1, x^51264 mod p(x)` << 1 */ + .octa 0x000000015168231600000000049c1c62 + + /* x^50176 mod p(x)` << 1, x^50240 mod p(x)` << 1 */ + .octa 0x0000000036fce78c000000017c460c12 + + /* x^49152 mod p(x)` << 1, x^49216 mod p(x)` << 1 */ + .octa 0x000000009037dc10000000015be4da7e + + /* x^48128 mod p(x)` << 1, x^48192 mod p(x)` << 1 */ + .octa 0x00000000d3298582000000010f38f668 + + /* x^47104 mod p(x)` << 1, x^47168 mod p(x)` << 1 */ + .octa 0x00000001b42e8ad60000000039f40a00 + + /* x^46080 mod p(x)` << 1, x^46144 mod p(x)` << 1 */ + .octa 0x00000000142a983800000000bd4c10c4 + + /* x^45056 mod p(x)` << 1, x^45120 mod p(x)` << 1 */ + .octa 0x0000000109c7f1900000000042db1d98 + + /* x^44032 mod p(x)` << 1, x^44096 mod p(x)` << 1 */ + .octa 0x0000000056ff931000000001c905bae6 + + /* x^43008 mod p(x)` << 1, x^43072 mod p(x)` << 1 */ + .octa 0x00000001594513aa00000000069d40ea + + /* x^41984 mod p(x)` << 1, x^42048 mod p(x)` << 1 */ + .octa 0x00000001e3b5b1e8000000008e4fbad0 + + /* x^40960 mod p(x)` << 1, x^41024 mod p(x)` << 1 */ + .octa 0x000000011dd5fc080000000047bedd46 + + /* x^39936 mod p(x)` << 1, x^40000 mod p(x)` << 1 */ + .octa 0x00000001675f0cc20000000026396bf8 + + /* x^38912 mod p(x)` << 1, x^38976 mod p(x)` << 1 */ + .octa 0x00000000d1c8dd4400000000379beb92 + + /* x^37888 mod p(x)` << 1, x^37952 mod p(x)` << 1 */ + .octa 0x0000000115ebd3d8000000000abae54a + + /* x^36864 mod p(x)` << 1, x^36928 mod p(x)` << 1 */ + .octa 0x00000001ecbd0dac0000000007e6a128 + + /* x^35840 mod p(x)` << 1, x^35904 mod p(x)` << 1 */ + .octa 0x00000000cdf67af2000000000ade29d2 + + /* x^34816 mod p(x)` << 1, x^34880 mod p(x)` << 1 */ + .octa 0x000000004c01ff4c00000000f974c45c + + /* x^33792 mod p(x)` << 1, x^33856 mod p(x)` << 1 */ + .octa 0x00000000f2d8657e00000000e77ac60a + + /* x^32768 mod p(x)` << 1, x^32832 mod p(x)` << 1 */ + .octa 0x000000006bae74c40000000145895816 + + /* x^31744 mod p(x)` << 1, x^31808 mod p(x)` << 1 */ + .octa 0x0000000152af8aa00000000038e362be + + /* x^30720 mod p(x)` << 1, x^30784 mod p(x)` << 1 */ + .octa 0x0000000004663802000000007f991a64 + + /* x^29696 mod p(x)` << 1, x^29760 mod p(x)` << 1 */ + .octa 0x00000001ab2f5afc00000000fa366d3a + + /* x^28672 mod p(x)` << 1, x^28736 mod p(x)` << 1 */ + .octa 0x0000000074a4ebd400000001a2bb34f0 + + /* x^27648 mod p(x)` << 1, x^27712 mod p(x)` << 1 */ + .octa 0x00000001d7ab3a4c0000000028a9981e + + /* x^26624 mod p(x)` << 1, x^26688 mod p(x)` << 1 */ + .octa 0x00000001a8da60c600000001dbc672be + + /* x^25600 mod p(x)` << 1, x^25664 mod p(x)` << 1 */ + .octa 0x000000013cf6382000000000b04d77f6 + + /* x^24576 mod p(x)` << 1, x^24640 mod p(x)` << 1 */ + .octa 0x00000000bec12e1e0000000124400d96 + + /* x^23552 mod p(x)` << 1, x^23616 mod p(x)` << 1 */ + .octa 0x00000001c6368010000000014ca4b414 + + /* x^22528 mod p(x)` << 1, x^22592 mod p(x)` << 1 */ + .octa 0x00000001e6e78758000000012fe2c938 + + /* x^21504 mod p(x)` << 1, x^21568 mod p(x)` << 1 */ + .octa 0x000000008d7f2b3c00000001faed01e6 + + /* x^20480 mod p(x)` << 1, x^20544 mod p(x)` << 1 */ + .octa 0x000000016b4a156e000000007e80ecfe + + /* x^19456 mod p(x)` << 1, x^19520 mod p(x)` << 1 */ + .octa 0x00000001c63cfeb60000000098daee94 + + /* x^18432 mod p(x)` << 1, x^18496 mod p(x)` << 1 */ + .octa 0x000000015f902670000000010a04edea + + /* x^17408 mod p(x)` << 1, x^17472 mod p(x)` << 1 */ + .octa 0x00000001cd5de11e00000001c00b4524 + + /* x^16384 mod p(x)` << 1, x^16448 mod p(x)` << 1 */ + .octa 0x000000001acaec540000000170296550 + + /* x^15360 mod p(x)` << 1, x^15424 mod p(x)` << 1 */ + .octa 0x000000002bd0ca780000000181afaa48 + + /* x^14336 mod p(x)` << 1, x^14400 mod p(x)` << 1 */ + .octa 0x0000000032d63d5c0000000185a31ffa + + /* x^13312 mod p(x)` << 1, x^13376 mod p(x)` << 1 */ + .octa 0x000000001c6d4e4c000000002469f608 + + /* x^12288 mod p(x)` << 1, x^12352 mod p(x)` << 1 */ + .octa 0x0000000106a60b92000000006980102a + + /* x^11264 mod p(x)` << 1, x^11328 mod p(x)` << 1 */ + .octa 0x00000000d3855e120000000111ea9ca8 + + /* x^10240 mod p(x)` << 1, x^10304 mod p(x)` << 1 */ + .octa 0x00000000e312563600000001bd1d29ce + + /* x^9216 mod p(x)` << 1, x^9280 mod p(x)` << 1 */ + .octa 0x000000009e8f7ea400000001b34b9580 + + /* x^8192 mod p(x)` << 1, x^8256 mod p(x)` << 1 */ + .octa 0x00000001c82e562c000000003076054e + + /* x^7168 mod p(x)` << 1, x^7232 mod p(x)` << 1 */ + .octa 0x00000000ca9f09ce000000012a608ea4 + + /* x^6144 mod p(x)` << 1, x^6208 mod p(x)` << 1 */ + .octa 0x00000000c63764e600000000784d05fe + + /* x^5120 mod p(x)` << 1, x^5184 mod p(x)` << 1 */ + .octa 0x0000000168d2e49e000000016ef0d82a + + /* x^4096 mod p(x)` << 1, x^4160 mod p(x)` << 1 */ + .octa 0x00000000e986c1480000000075bda454 + + /* x^3072 mod p(x)` << 1, x^3136 mod p(x)` << 1 */ + .octa 0x00000000cfb65894000000003dc0a1c4 + + /* x^2048 mod p(x)` << 1, x^2112 mod p(x)` << 1 */ + .octa 0x0000000111cadee400000000e9a5d8be + + /* x^1024 mod p(x)` << 1, x^1088 mod p(x)` << 1 */ + .octa 0x0000000171fb63ce00000001609bc4b4 + +SHORT_CONSTANTS: + + /* Reduce final 1024-2048 bits to 64 bits, shifting 32 bits to include the trailing 32 bits of zeros */ + /* x^1952 mod p(x)`, x^1984 mod p(x)`, x^2016 mod p(x)`, x^2048 mod p(x)` */ + .octa 0x7fec2963e5bf80485cf015c388e56f72 + + /* x^1824 mod p(x)`, x^1856 mod p(x)`, x^1888 mod p(x)`, x^1920 mod p(x)` */ + .octa 0x38e888d4844752a9963a18920246e2e6 + + /* x^1696 mod p(x)`, x^1728 mod p(x)`, x^1760 mod p(x)`, x^1792 mod p(x)` */ + .octa 0x42316c00730206ad419a441956993a31 + + /* x^1568 mod p(x)`, x^1600 mod p(x)`, x^1632 mod p(x)`, x^1664 mod p(x)` */ + .octa 0x543d5c543e65ddf9924752ba2b830011 + + /* x^1440 mod p(x)`, x^1472 mod p(x)`, x^1504 mod p(x)`, x^1536 mod p(x)` */ + .octa 0x78e87aaf56767c9255bd7f9518e4a304 + + /* x^1312 mod p(x)`, x^1344 mod p(x)`, x^1376 mod p(x)`, x^1408 mod p(x)` */ + .octa 0x8f68fcec1903da7f6d76739fe0553f1e + + /* x^1184 mod p(x)`, x^1216 mod p(x)`, x^1248 mod p(x)`, x^1280 mod p(x)` */ + .octa 0x3f4840246791d588c133722b1fe0b5c3 + + /* x^1056 mod p(x)`, x^1088 mod p(x)`, x^1120 mod p(x)`, x^1152 mod p(x)` */ + .octa 0x34c96751b04de25a64b67ee0e55ef1f3 + + /* x^928 mod p(x)`, x^960 mod p(x)`, x^992 mod p(x)`, x^1024 mod p(x)` */ + .octa 0x156c8e180b4a395b069db049b8fdb1e7 + + /* x^800 mod p(x)`, x^832 mod p(x)`, x^864 mod p(x)`, x^896 mod p(x)` */ + .octa 0xe0b99ccbe661f7bea11bfaf3c9e90b9e + + /* x^672 mod p(x)`, x^704 mod p(x)`, x^736 mod p(x)`, x^768 mod p(x)` */ + .octa 0x041d37768cd75659817cdc5119b29a35 + + /* x^544 mod p(x)`, x^576 mod p(x)`, x^608 mod p(x)`, x^640 mod p(x)` */ + .octa 0x3a0777818cfaa9651ce9d94b36c41f1c + + /* x^416 mod p(x)`, x^448 mod p(x)`, x^480 mod p(x)`, x^512 mod p(x)` */ + .octa 0x0e148e8252377a554f256efcb82be955 + + /* x^288 mod p(x)`, x^320 mod p(x)`, x^352 mod p(x)`, x^384 mod p(x)` */ + .octa 0x9c25531d19e65ddeec1631edb2dea967 + + /* x^160 mod p(x)`, x^192 mod p(x)`, x^224 mod p(x)`, x^256 mod p(x)` */ + .octa 0x790606ff9957c0a65d27e147510ac59a + + /* x^32 mod p(x)`, x^64 mod p(x)`, x^96 mod p(x)`, x^128 mod p(x)` */ + .octa 0x82f63b786ea2d55ca66805eb18b8ea18 + + +BARRETT_CONSTANTS: + /* 33 bit reflected Barrett constant m - (4^32)/n */ + .octa 0x000000000000000000000000dea713f1 /* x^64 div p(x)` */ + /* 33 bit reflected Barrett constant n */ + .octa 0x00000000000000000000000105ec76f1 + +#endif /* __powerpc__ */ + +#endif diff --git a/mysys/crc32_power8/crc32c_wrapper.c b/mysys/crc32_power8/crc32c_wrapper.c new file mode 100644 index 0000000..b121d3e --- /dev/null +++ b/mysys/crc32_power8/crc32c_wrapper.c @@ -0,0 +1,78 @@ +#ifdef __powerpc__ + +#define F crc32c_vpmsum +#define __F __crc32c_vpmsum + +#define CRC 0x1edc6f41 + +static const unsigned int crc_table[] = { + 0x00000000, 0xf26b8303, 0xe13b70f7, 0x1350f3f4, + 0xc79a971f, 0x35f1141c, 0x26a1e7e8, 0xd4ca64eb, + 0x8ad958cf, 0x78b2dbcc, 0x6be22838, 0x9989ab3b, + 0x4d43cfd0, 0xbf284cd3, 0xac78bf27, 0x5e133c24, + 0x105ec76f, 0xe235446c, 0xf165b798, 0x030e349b, + 0xd7c45070, 0x25afd373, 0x36ff2087, 0xc494a384, + 0x9a879fa0, 0x68ec1ca3, 0x7bbcef57, 0x89d76c54, + 0x5d1d08bf, 0xaf768bbc, 0xbc267848, 0x4e4dfb4b, + 0x20bd8ede, 0xd2d60ddd, 0xc186fe29, 0x33ed7d2a, + 0xe72719c1, 0x154c9ac2, 0x061c6936, 0xf477ea35, + 0xaa64d611, 0x580f5512, 0x4b5fa6e6, 0xb93425e5, + 0x6dfe410e, 0x9f95c20d, 0x8cc531f9, 0x7eaeb2fa, + 0x30e349b1, 0xc288cab2, 0xd1d83946, 0x23b3ba45, + 0xf779deae, 0x05125dad, 0x1642ae59, 0xe4292d5a, + 0xba3a117e, 0x4851927d, 0x5b016189, 0xa96ae28a, + 0x7da08661, 0x8fcb0562, 0x9c9bf696, 0x6ef07595, + 0x417b1dbc, 0xb3109ebf, 0xa0406d4b, 0x522bee48, + 0x86e18aa3, 0x748a09a0, 0x67dafa54, 0x95b17957, + 0xcba24573, 0x39c9c670, 0x2a993584, 0xd8f2b687, + 0x0c38d26c, 0xfe53516f, 0xed03a29b, 0x1f682198, + 0x5125dad3, 0xa34e59d0, 0xb01eaa24, 0x42752927, + 0x96bf4dcc, 0x64d4cecf, 0x77843d3b, 0x85efbe38, + 0xdbfc821c, 0x2997011f, 0x3ac7f2eb, 0xc8ac71e8, + 0x1c661503, 0xee0d9600, 0xfd5d65f4, 0x0f36e6f7, + 0x61c69362, 0x93ad1061, 0x80fde395, 0x72966096, + 0xa65c047d, 0x5437877e, 0x4767748a, 0xb50cf789, + 0xeb1fcbad, 0x197448ae, 0x0a24bb5a, 0xf84f3859, + 0x2c855cb2, 0xdeeedfb1, 0xcdbe2c45, 0x3fd5af46, + 0x7198540d, 0x83f3d70e, 0x90a324fa, 0x62c8a7f9, + 0xb602c312, 0x44694011, 0x5739b3e5, 0xa55230e6, + 0xfb410cc2, 0x092a8fc1, 0x1a7a7c35, 0xe811ff36, + 0x3cdb9bdd, 0xceb018de, 0xdde0eb2a, 0x2f8b6829, + 0x82f63b78, 0x709db87b, 0x63cd4b8f, 0x91a6c88c, + 0x456cac67, 0xb7072f64, 0xa457dc90, 0x563c5f93, + 0x082f63b7, 0xfa44e0b4, 0xe9141340, 0x1b7f9043, + 0xcfb5f4a8, 0x3dde77ab, 0x2e8e845f, 0xdce5075c, + 0x92a8fc17, 0x60c37f14, 0x73938ce0, 0x81f80fe3, + 0x55326b08, 0xa759e80b, 0xb4091bff, 0x466298fc, + 0x1871a4d8, 0xea1a27db, 0xf94ad42f, 0x0b21572c, + 0xdfeb33c7, 0x2d80b0c4, 0x3ed04330, 0xccbbc033, + 0xa24bb5a6, 0x502036a5, 0x4370c551, 0xb11b4652, + 0x65d122b9, 0x97baa1ba, 0x84ea524e, 0x7681d14d, + 0x2892ed69, 0xdaf96e6a, 0xc9a99d9e, 0x3bc21e9d, + 0xef087a76, 0x1d63f975, 0x0e330a81, 0xfc588982, + 0xb21572c9, 0x407ef1ca, 0x532e023e, 0xa145813d, + 0x758fe5d6, 0x87e466d5, 0x94b49521, 0x66df1622, + 0x38cc2a06, 0xcaa7a905, 0xd9f75af1, 0x2b9cd9f2, + 0xff56bd19, 0x0d3d3e1a, 0x1e6dcdee, 0xec064eed, + 0xc38d26c4, 0x31e6a5c7, 0x22b65633, 0xd0ddd530, + 0x0417b1db, 0xf67c32d8, 0xe52cc12c, 0x1747422f, + 0x49547e0b, 0xbb3ffd08, 0xa86f0efc, 0x5a048dff, + 0x8ecee914, 0x7ca56a17, 0x6ff599e3, 0x9d9e1ae0, + 0xd3d3e1ab, 0x21b862a8, 0x32e8915c, 0xc083125f, + 0x144976b4, 0xe622f5b7, 0xf5720643, 0x07198540, + 0x590ab964, 0xab613a67, 0xb831c993, 0x4a5a4a90, + 0x9e902e7b, 0x6cfbad78, 0x7fab5e8c, 0x8dc0dd8f, + 0xe330a81a, 0x115b2b19, 0x020bd8ed, 0xf0605bee, + 0x24aa3f05, 0xd6c1bc06, 0xc5914ff2, 0x37faccf1, + 0x69e9f0d5, 0x9b8273d6, 0x88d28022, 0x7ab90321, + 0xae7367ca, 0x5c18e4c9, 0x4f48173d, 0xbd23943e, + 0xf36e6f75, 0x0105ec76, 0x12551f82, 0xe03e9c81, + 0x34f4f86a, 0xc69f7b69, 0xd5cf889d, 0x27a40b9e, + 0x79b737ba, 0x8bdcb4b9, 0x988c474d, 0x6ae7c44e, + 0xbe2da0a5, 0x4c4623a6, 0x5f16d052, 0xad7d5351,}; + + +#include "crc32_wrapper.ic" + +#endif + diff --git a/mysys/crc32_power8/ppc-opcode.h b/mysys/crc32_power8/ppc-opcode.h new file mode 100644 index 0000000..5942bd4 --- /dev/null +++ b/mysys/crc32_power8/ppc-opcode.h @@ -0,0 +1,23 @@ +#ifndef __OPCODES_H +#define __OPCODES_H + +#define __PPC_RA(a) (((a) & 0x1f) << 16) +#define __PPC_RB(b) (((b) & 0x1f) << 11) +#define __PPC_XA(a) ((((a) & 0x1f) << 16) | (((a) & 0x20) >> 3)) +#define __PPC_XB(b) ((((b) & 0x1f) << 11) | (((b) & 0x20) >> 4)) +#define __PPC_XS(s) ((((s) & 0x1f) << 21) | (((s) & 0x20) >> 5)) +#define __PPC_XT(s) __PPC_XS(s) +#define VSX_XX3(t, a, b) (__PPC_XT(t) | __PPC_XA(a) | __PPC_XB(b)) +#define VSX_XX1(s, a, b) (__PPC_XS(s) | __PPC_RA(a) | __PPC_RB(b)) + +#define PPC_INST_VPMSUMW 0x10000488 +#define PPC_INST_VPMSUMD 0x100004c8 +#define PPC_INST_MFVSRD 0x7c000066 +#define PPC_INST_MTVSRD 0x7c000166 + +#define VPMSUMW(t, a, b) .long PPC_INST_VPMSUMW | VSX_XX3((t), a, b) +#define VPMSUMD(t, a, b) .long PPC_INST_VPMSUMD | VSX_XX3((t), a, b) +#define MFVRD(a, t) .long PPC_INST_MFVSRD | VSX_XX1((t)+32, a, 0) +#define MTVRD(t, a) .long PPC_INST_MTVSRD | VSX_XX1((t)+32, a, 0) + +#endif diff --git a/mysys/ut0crc32.cc b/mysys/ut0crc32.cc index 6f154e4..45b4e32 100644 --- a/mysys/ut0crc32.cc +++ b/mysys/ut0crc32.cc @@ -84,6 +84,10 @@ mysys/my_perf.c, contributed by Facebook under the following license. #include "ut0crc32.h" +#if defined(__linux__) && defined(__powerpc__) +#include +#endif + /** Pointer to CRC32C calculation function. */ ut_crc32_func_t ut_crc32c; @@ -433,6 +437,62 @@ static bool ut_crc32c_slice8_table_initialized = false; static uint32 ut_crc32_slice8_table[8][256]; static bool ut_crc32_slice8_table_initialized = false; +#if defined(__powerpc__) +extern "C" { +unsigned int crc32c_vpmsum(unsigned int crc, const unsigned char *p, unsigned long len); +unsigned int crc32_vpmsum(unsigned int crc, const unsigned char *p, unsigned long len); +}; +#endif /* __powerpc__ */ + +inline +uint32 +ut_crc32c_power8( +/*===========*/ + const uint8* buf, /*!< in: data over which to calculate CRC32 */ + my_ulonglong len) /*!< in: data length */ +{ +#if defined(__powerpc__) && !defined(WORDS_BIGENDIAN) + return crc32c_vpmsum(0, buf, len); +#else + MY_ASSERT_UNREACHABLE(); + /* silence compiler warning about unused parameters */ + return((uint32) buf[len]); +#endif /* __powerpc__ */ +} + +inline +uint32 +ut_crc32_power8( +/*===========*/ + const uint8* buf, /*!< in: data over which to calculate CRC32 */ + my_ulonglong len) /*!< in: data length */ +{ +#if defined(__powerpc__) && !defined(WORDS_BIGENDIAN) + return crc32_vpmsum(0, buf, len); +#else + MY_ASSERT_UNREACHABLE(); + /* silence compiler warning about unused parameters */ + return((uint32) buf[len]); +#endif /* __powerpc__ */ +} + +inline +uint32 +ut_crc32_ex_power8( +/*===========*/ + uint32 crc, /*!< in: crc so far which we are adding to */ + const uint8* buf, /*!< in: data over which to calculate CRC32 */ + my_ulonglong len) /*!< in: data length */ +{ +#if defined(__powerpc__) && !defined(WORDS_BIGENDIAN) + return crc32_vpmsum(crc, buf, len); +#else + MY_ASSERT_UNREACHABLE(); + /* silence compiler warning about unused parameters */ + return((uint32) buf[len]); +#endif /* __powerpc__ */ +} + /********************************************************************//** Initializes the table that is used to generate the CRC32 if the CPU does not have support for it. */ @@ -778,7 +838,14 @@ void ut_crc32_init() /*===========*/ { - my_bool ut_crc32_sse2_enabled = false; + my_bool ut_crc32_power8_enabled = false; + +#if defined(__linux__) && defined(__powerpc__) && defined(AT_HWCAP2) && + !defined(WORDS_BIGENDIAN) + if (getauxval(AT_HWCAP2) & PPC_FEATURE2_ARCH_2_07) + ut_crc32_power8_enabled = true; +#endif /* defined(__linux__) && defined(__powerpc__) */ + #if defined(__GNUC__) && defined(__x86_64__) uint32 vend[3]; uint32 model; @@ -786,6 +853,7 @@ ut_crc32_init() uint32 stepping; uint32 features_ecx; uint32 features_edx; + my_bool ut_crc32_sse2_enabled = false; ut_cpuid(vend, &model, &family, &stepping, &features_ecx, &features_edx); @@ -810,6 +878,7 @@ ut_crc32_init() ut_crc32_sse2_enabled = (features_ecx >> 20) & 1; #endif /* UNIV_DEBUG_VALGRIND */ + if (ut_crc32_sse2_enabled) { ut_crc32c = ut_crc32c_hw; ut_crc32c_legacy_big_endian = ut_crc32c_legacy_big_endian_hw; @@ -819,11 +888,21 @@ ut_crc32_init() ut_crc32 = ut_crc32_sw; ut_crc32_ex = ut_crc32_ex_sw; ut_crc32_implementation = "Using SSE2 crc32c instructions"; - } - + } else #endif /* defined(__GNUC__) && defined(__x86_64__) */ + if (ut_crc32_power8_enabled) { + ut_crc32c = ut_crc32c_power8; + ut_crc32c_slice8_table_init(); + ut_crc32c_legacy_big_endian = ut_crc32c_legacy_big_endian_sw; + ut_crc32c_byte_by_byte = ut_crc32c_byte_by_byte_sw; + + ut_crc32 = ut_crc32_power8; + ut_crc32_ex = ut_crc32_ex_power8; + ut_crc32_implementation = "Using POWER8 crc32c instructions"; + ut_crc32_ex = ut_crc32_ex_sw; + ut_crc32_implementation = "Using SSE2 crc32c instructions"; - if (!ut_crc32_sse2_enabled) { + } else { ut_crc32c_slice8_table_init(); ut_crc32c = ut_crc32c_sw; ut_crc32c_legacy_big_endian = ut_crc32c_legacy_big_endian_sw; From e66eb164e77871dbb4d1a9bdac66894267537083 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Wed, 23 Mar 2016 11:14:22 +1100 Subject: [PATCH 12/12] CRC32 no longer needed from zlib --- cmake/zlib.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmake/zlib.cmake b/cmake/zlib.cmake index d1bd034..7121670 100644 --- a/cmake/zlib.cmake +++ b/cmake/zlib.cmake @@ -53,11 +53,10 @@ MACRO (MYSQL_CHECK_ZLIB_WITH_COMPRESS) IF(ZLIB_FOUND) INCLUDE(CheckFunctionExists) SET(CMAKE_REQUIRED_LIBRARIES z) - CHECK_FUNCTION_EXISTS(crc32 HAVE_CRC32) CHECK_FUNCTION_EXISTS(compressBound HAVE_COMPRESSBOUND) CHECK_FUNCTION_EXISTS(deflateBound HAVE_DEFLATEBOUND) SET(CMAKE_REQUIRED_LIBRARIES) - IF(HAVE_CRC32 AND HAVE_COMPRESSBOUND AND HAVE_DEFLATEBOUND) + IF(HAVE_COMPRESSBOUND AND HAVE_DEFLATEBOUND) SET(ZLIB_LIBRARY ${ZLIB_LIBRARIES} CACHE INTERNAL "System zlib library") SET(WITH_ZLIB "system" CACHE STRING "Which zlib to use (possible values are 'bundled' or 'system')")