From 8758b4a88c948e8abffe2a866dc6319f982e7181 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 18 Dec 2015 13:07:04 +1100 Subject: [PATCH 1/8] Move crc32 implementation from storage/innodb to mysys Prepares for common use of implementation of: Bug#79155 optimized crc32 for CRC32() function Bug#79325 optimized crc32 for binary log checksums --- extra/CMakeLists.txt | 4 +- include/ut0crc32.h | 60 +++ mysys/CMakeLists.txt | 9 + mysys/ut0crc32.cc | 736 ++++++++++++++++++++++++++++++++++++ storage/innobase/CMakeLists.txt | 10 +- storage/innobase/include/ut0crc32.h | 60 --- storage/innobase/ut/ut0crc32.cc | 736 ------------------------------------ 7 files changed, 808 insertions(+), 807 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 713b3c6..747d54f 100644 --- a/extra/CMakeLists.txt +++ b/extra/CMakeLists.txt @@ -111,7 +111,7 @@ IF(WITH_INNOBASE_STORAGE_ENGINE) ADD_DEFINITIONS("-DUNIV_INNOCHECKSUM") SET(INNOBASE_SOURCES ../storage/innobase/buf/buf0checksum.cc - ../storage/innobase/ut/ut0crc32.cc + ../mysys/ut0crc32.cc ../storage/innobase/ut/ut0ut.cc ../storage/innobase/buf/buf0buf.cc ../storage/innobase/page/page0zip.cc @@ -123,7 +123,7 @@ IF(WITH_INNOBASE_STORAGE_ENGINE) CMAKE_SYSTEM_PROCESSOR MATCHES "i386") INCLUDE(${MYSQL_CMAKE_SCRIPT_DIR}/compile_flags.cmake) ADD_COMPILE_FLAGS( - ../storage/innobase/ut/ut0crc32.cc + ../mysys/ut0crc32.cc COMPILE_FLAGS "-Wa,-nH" ) ENDIF() diff --git a/include/ut0crc32.h b/include/ut0crc32.h new file mode 100644 index 0000000..04eb9e0 --- /dev/null +++ b/include/ut0crc32.h @@ -0,0 +1,60 @@ +/***************************************************************************** + +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/mysys/CMakeLists.txt b/mysys/CMakeLists.txt index a9846b9..0e53ccd 100644 --- a/mysys/CMakeLists.txt +++ b/mysys/CMakeLists.txt @@ -54,6 +54,15 @@ IF(HAVE_KQUEUE_TIMERS) SET(MYSYS_SOURCES ${MYSYS_SOURCES} kqueue_timers.c) 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) + ADD_COMPILE_FLAGS( + ut0crc32.cc + COMPILE_FLAGS "-Wa,-nH" + ) +ENDIF() + IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND CMAKE_C_COMPILER_ID MATCHES "SunPro") # Inline assembly template for rdtsc SET_SOURCE_FILES_PROPERTIES(my_rdtsc.c diff --git a/mysys/ut0crc32.cc b/mysys/ut0crc32.cc new file mode 100644 index 0000000..979713f --- /dev/null +++ b/mysys/ut0crc32.cc @@ -0,0 +1,736 @@ +/***************************************************************************** + +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; + } +} diff --git a/storage/innobase/CMakeLists.txt b/storage/innobase/CMakeLists.txt index 1667b9d..8277311 100644 --- a/storage/innobase/CMakeLists.txt +++ b/storage/innobase/CMakeLists.txt @@ -133,7 +133,7 @@ SET(INNOBASE_SOURCES trx/trx0undo.cc usr/usr0sess.cc ut/ut0byte.cc - ut/ut0crc32.cc + ../../mysys/ut0crc32.cc ut/ut0dbg.cc ut/ut0list.cc ut/ut0mem.cc @@ -158,14 +158,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) - ADD_COMPILE_FLAGS( - ut/ut0crc32.cc - COMPILE_FLAGS "-Wa,-nH" - ) -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. 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 392b0ca1f657e4ebd7dff529bf42c41439c23ea6 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 18 Dec 2015 13:15:03 +1100 Subject: [PATCH 2/8] Add common text description of crc32 for logging Facilitates expansion of description for other optmised crc32 implementations: Bug#74776 InnoDB checksums (new or crc32) use too much CPU on POWER8 Bug#79144 No hardware CRC32 implementation for AArch64 --- include/ut0crc32.h | 4 ++-- mysys/ut0crc32.cc | 16 ++++++---------- storage/innobase/srv/srv0start.cc | 3 +-- unittest/gunit/innodb/ut0crc32-t.cc | 4 +--- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/include/ut0crc32.h b/include/ut0crc32.h index 04eb9e0..ab5ecc6 100644 --- a/include/ut0crc32.h +++ b/include/ut0crc32.h @@ -54,7 +54,7 @@ extern ut_crc32_func_t ut_crc32_legacy_big_endian; 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; +/** Text description of CRC32 implementation */ +extern const char *ut_crc32_implementation; #endif /* ut0crc32_h */ diff --git a/mysys/ut0crc32.cc b/mysys/ut0crc32.cc index 979713f..5333ef7 100644 --- a/mysys/ut0crc32.cc +++ b/mysys/ut0crc32.cc @@ -88,6 +88,9 @@ mysys/my_perf.c, contributed by Facebook under the following license. /** Pointer to CRC32 calculation function. */ ut_crc32_func_t ut_crc32; +/** Text description of CRC32 implementation */ +const char *ut_crc32_implementation = NULL; + /** 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; @@ -114,10 +117,6 @@ ut_crc32_swap_byteorder( | 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__) /********************************************************************//** @@ -268,8 +267,6 @@ ut_crc32_hw( { 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) { @@ -359,8 +356,6 @@ ut_crc32_legacy_big_endian_hw( { 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) { @@ -411,8 +406,6 @@ ut_crc32_byte_by_byte_hw( { uint32_t crc = 0xFFFFFFFFU; - ut_a(ut_crc32_sse2_enabled); - while (len > 0) { ut_crc32_8_hw(&crc, &buf, &len); } @@ -688,6 +681,7 @@ void ut_crc32_init() /*===========*/ { + bool ut_crc32_sse2_enabled = false; #if defined(__GNUC__) && defined(__x86_64__) uint32_t vend[3]; uint32_t model; @@ -723,6 +717,7 @@ ut_crc32_init() 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_crc32_implementation = "SSE2 crc32 instructions"; } #endif /* defined(__GNUC__) && defined(__x86_64__) */ @@ -732,5 +727,6 @@ ut_crc32_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_crc32_implementation = "Software implemented crc32"; } } diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index cd11f70..6b08025 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -1672,8 +1672,7 @@ innobase_start_or_create_for_mysql(void) srv_boot(); - ib::info() << (ut_crc32_sse2_enabled ? "Using" : "Not using") - << " CPU crc32 instructions"; + ib::info() << "Using " << 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 0e13081..bf08eb19 100644 --- a/unittest/gunit/innodb/ut0crc32-t.cc +++ b/unittest/gunit/innodb/ut0crc32-t.cc @@ -2088,9 +2088,7 @@ init() ut_crc32_init(); fprintf(stderr, "Using %s, CPU is %s-endian ", - ut_crc32_sse2_enabled - ? "hardware CPU crc32 instructions" - : "software crc32 implementation", + ut_crc32_implementation, #ifdef WORDS_BIGENDIAN "big" #else /* WORDS_BIGENDIAN */ From f95abb7d91fda72b324ada103e3b501bcc8cf959 Mon Sep 17 00:00:00 2001 From: Anton Blanchard Date: Fri, 18 Dec 2015 13:30:11 +1100 Subject: [PATCH 3/8] Add POWER8 optimized crc32 code ref: https://github.com/antonblanchard/crc32-vpmsum Bug#79144: No hardware CRC32 implementation for AArch64#74776 InnoDB checksums (new or crc32) use too much CPU on POWER8 --- mysys/crc32_power8/crc32.S | 744 ++++++++++++++++++++++++++++ mysys/crc32_power8/crc32_constants.h | 911 +++++++++++++++++++++++++++++++++++ mysys/crc32_power8/crc32_wrapper.c | 68 +++ mysys/crc32_power8/ppc-opcode.h | 23 + 4 files changed, 1746 insertions(+) create mode 100644 mysys/crc32_power8/crc32.S create mode 100644 mysys/crc32_power8/crc32_constants.h create mode 100644 mysys/crc32_power8/crc32_wrapper.c create mode 100644 mysys/crc32_power8/ppc-opcode.h diff --git a/mysys/crc32_power8/crc32.S b/mysys/crc32_power8/crc32.S new file mode 100644 index 0000000..52046bb --- /dev/null +++ b/mysys/crc32_power8/crc32.S @@ -0,0 +1,744 @@ +/* + * 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 + +#define __ASSEMBLY__ +#include "crc32_constants.h" + + .text + +#if defined(__BIG_ENDIAN__) && defined(REFLECT) +#define BYTESWAP_DATA +#elif defined(__LITTLE_ENDIAN__) && !defined(REFLECT) +#define BYTESWAP_DATA +#else +#undef BYTESWAP_DATA +#endif + +#define off16 r25 +#define off32 r26 +#define off48 r27 +#define off64 r28 +#define off80 r29 +#define off96 r30 +#define off112 r31 + +#define const1 v25 +#define const2 v26 + +#define byteswap v27 +#define mask_32bit v28 +#define mask_64bit v29 +#define zeroes v30 +#define ones v31 + +#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(__crc32_vpmsum) + 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 + + mr r10,r3 + + vxor zeroes,zeroes,zeroes + vspltisw ones,-1 + + vsldoi mask_32bit,zeroes,ones,4 + vsldoi mask_64bit,zeroes,ones,8 + + /* Get the initial value into v8 */ + vxor v8,v8,v8 + MTVRD(v8, r3) +#ifdef REFLECT + vsldoi v8,zeroes,v8,8 /* shift into bottom 32 bits */ +#else + vsldoi v8,v8,zeroes,4 /* shift into top 32 bits */ +#endif + +#ifdef BYTESWAP_DATA + addis r3,r2,.byteswap_constant@toc@ha + addi r3,r3,.byteswap_constant@toc@l + + lvx byteswap,0,r3 + addi r3,r3,16 +#endif + + 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 + +#ifdef REFLECT + /* + * 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 +#endif + + /* 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 */ + +#ifdef REFLECT + /* shift left one bit */ + vspltisb v1,1 + vsl v0,v0,v1 +#endif + + vand v0,v0,mask_64bit + +#ifndef REFLECT + /* + * Now for the Barrett reduction algorithm. The idea is to calculate q, + * the multiple of our polynomial that we need to subtract. By + * doing the computation 2x bits higher (ie 64 bits) and shifting the + * result back down 2x bits, we round down to the nearest multiple. + */ + VPMSUMD(v1,v0,const1) /* ma */ + vsldoi v1,zeroes,v1,8 /* q = floor(ma/(2^64)) */ + VPMSUMD(v1,v1,const2) /* qn */ + vxor v0,v0,v1 /* a - qn, subtraction is xor in GF(2) */ + + /* + * Get the result into r3. We need to shift it left 8 bytes: + * V0 [ 0 1 2 X ] + * V0 [ 0 X 2 3 ] + */ + vsldoi v0,v0,zeroes,8 /* shift result into top 64 bits */ +#else + /* + * 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 */ +#endif + + /* 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 +FUNC_END(__crc32_vpmsum) + +#endif /* __powerpc__ */ diff --git a/mysys/crc32_power8/crc32_constants.h b/mysys/crc32_power8/crc32_constants.h new file mode 100644 index 0000000..ba2592b --- /dev/null +++ b/mysys/crc32_power8/crc32_constants.h @@ -0,0 +1,911 @@ +#ifndef CRC32_CONSTANTS_H +#define CRC32_CONSTANTS_H + +#ifdef __powerpc__ + + +#define CRC 0x1edc6f41 +#define CRC_XOR +#define REFLECT + +#ifndef __ASSEMBLY__ +#ifdef CRC_TABLE +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,}; + +#endif +#else +#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 + +#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..d4c9137 --- /dev/null +++ b/mysys/crc32_power8/crc32_wrapper.c @@ -0,0 +1,68 @@ +#ifdef __powerpc__ + +#define CRC_TABLE +#include "crc32_constants.h" + +#define VMX_ALIGN 16 +#define VMX_ALIGN_MASK (VMX_ALIGN-1) + +#ifdef REFLECT +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; +} +#else +static unsigned int crc32_align(unsigned int crc, unsigned char *p, + unsigned long len) +{ + while (len--) + crc = crc_table[((crc >> 24) ^ *p++) & 0xff] ^ (crc << 8); + return crc; +} +#endif + +unsigned int __crc32_vpmsum(unsigned int crc, unsigned char *p, + unsigned long len); + +unsigned int crc32_vpmsum(unsigned int crc, unsigned char *p, + unsigned long len) +{ + unsigned int prealign; + unsigned int tail; + +#ifdef CRC_XOR + crc ^= 0xffffffff; +#endif + + 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 = __crc32_vpmsum(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: +#ifdef CRC_XOR + crc ^= 0xffffffff; +#endif + + return crc; +} + +#endif /* __powerpc__ */ 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 From 314d713cffa804179f15b5bcc29367e9d0fb0cb7 Mon Sep 17 00:00:00 2001 From: Daniel Axtens Date: Fri, 18 Dec 2015 13:31:46 +1100 Subject: [PATCH 4/8] Hook power8 crc32 implementation in for linux ppc64le platform This is only used on Linux where we detect (at runtime) that ARCH_2_07 is available (which has the necessary hardware instructions). Bug#74776 InnoDB checksums (new or crc32) use too much CPU on POWER8 --- extra/CMakeLists.txt | 7 +++++++ mysys/CMakeLists.txt | 7 +++++++ mysys/ut0crc32.cc | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/extra/CMakeLists.txt b/extra/CMakeLists.txt index 747d54f..5b3bff5 100644 --- a/extra/CMakeLists.txt +++ b/extra/CMakeLists.txt @@ -118,6 +118,13 @@ IF(WITH_INNOBASE_STORAGE_ENGINE) ../storage/innobase/os/os0file.cc ) + IF(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le") + enable_language(ASM) + LIST(APPEND INNOBASE_SOURCES + ../mysys/crc32_power8/crc32.S + ../mysys/crc32_power8/crc32_wrapper.c) + ENDIF() + # Avoid generating Hardware Capabilities due to crc32 instructions IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND CMAKE_SYSTEM_PROCESSOR MATCHES "i386") diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt index 0e53ccd..ceda2c1 100644 --- a/mysys/CMakeLists.txt +++ b/mysys/CMakeLists.txt @@ -36,6 +36,13 @@ 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) +IF(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le") + enable_language(ASM) + LIST(APPEND MYSYS_SOURCES + crc32_power8/crc32.S + crc32_power8/crc32_wrapper.c) +ENDIF() + IF (WIN32) LIST(APPEND MYSYS_SOURCES my_conio.c diff --git a/mysys/ut0crc32.cc b/mysys/ut0crc32.cc index 5333ef7..0bfdcef 100644 --- a/mysys/ut0crc32.cc +++ b/mysys/ut0crc32.cc @@ -82,6 +82,12 @@ mysys/my_perf.c, contributed by Facebook under the following license. #include "my_config.h" #include +#if defined(__linux__) && defined(__powerpc__) +/* Used to detect at runtime if we have vpmsum instructions (PowerISA 2.07) */ +#include +#include +#endif /* defined(__linux__) && defined(__powerpc__) */ + #include "univ.i" #include "ut0crc32.h" @@ -421,6 +427,28 @@ have support for it */ static uint32_t ut_crc32_slice8_table[8][256]; static bool ut_crc32_slice8_table_initialized = false; +#if defined(__powerpc__) +extern "C" { +unsigned int crc32_vpmsum(unsigned int crc, const unsigned char *p, unsigned long len); +}; +#endif /* __powerpc__ */ + +UNIV_INLINE +ib_uint32_t +ut_crc32_power8( +/*===========*/ + const byte* buf, /*!< in: data over which to calculate CRC32 */ + ulint len) /*!< in: data length */ +{ +#if defined(__powerpc__) + return crc32_vpmsum(0, buf, len); +#else + ut_error; + /* silence compiler warning about unused parameters */ + return((ib_uint32_t) buf[len]); +#endif /* __powerpc__ */ +} + /********************************************************************//** Initializes the table that is used to generate the CRC32 if the CPU does not have support for it. */ @@ -722,6 +750,16 @@ ut_crc32_init() #endif /* defined(__GNUC__) && defined(__x86_64__) */ +#if defined(__linux__) && defined(__powerpc__) && defined(AT_HWCAP2) + if (getauxval(AT_HWCAP2) & PPC_FEATURE2_ARCH_2_07) { + ut_crc32_implementation = "POWER8 crc32 instructions"; + ut_crc32 = ut_crc32_power8; + ut_crc32_legacy_big_endian = ut_crc32_legacy_big_endian_sw; + ut_crc32_byte_by_byte = ut_crc32_byte_by_byte_sw; + /* needed for ut_crc32_legacy_big_endian_sw */ + ut_crc32_slice8_table_init(); + } else +#endif /* defined(__linux__) && defined(__powerpc__) */ if (!ut_crc32_sse2_enabled) { ut_crc32_slice8_table_init(); ut_crc32 = ut_crc32_sw; From a0e2c4f7cbd0894f8413c98229ef4250c73f9109 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 18 Dec 2015 14:22:28 +1100 Subject: [PATCH 5/8] Initialise crc32 globally To facilitate: Bug#79155 optimized crc32 for CRC32() function Bug#79325 optimized crc32 for binary log checksums --- sql/mysqld.cc | 3 +++ storage/innobase/srv/srv0srv.cc | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 740c5d5..5de5018 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -141,6 +141,7 @@ #include "item_cmpfunc.h" // arg_cmp_func #include "item_strfunc.h" // Item_func_uuid #include "handler.h" +#include "ut0crc32.h" // ut_crc32_init #ifndef EMBEDDED_LIBRARY #include "srv_session.h" @@ -4428,6 +4429,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 4171a81..ebaa566 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. */ @@ -1004,8 +1003,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(); } From 756b908052b76a2245e19b824a9a7516b46df8d6 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Mon, 21 Dec 2015 11:54:45 +1100 Subject: [PATCH 6/8] Remove crc32 dependency on univ.i --- include/ut0crc32.h | 20 +++++++++++++++++++- mysys/ut0crc32.cc | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/include/ut0crc32.h b/include/ut0crc32.h index ab5ecc6..b7f6942 100644 --- a/include/ut0crc32.h +++ b/include/ut0crc32.h @@ -26,7 +26,25 @@ Created Aug 10, 2011 Vasil Dimov #ifndef ut0crc32_h #define ut0crc32_h -#include "univ.i" +#ifndef byte +#define byte unsigned char +#endif + +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif +/* #include "univ.i" defines ULINTPF and types within storage/innodb but + * we duplicated those here since crc32 is used globally */ +#ifndef ULINTPF +#ifdef _WIN64 +typedef unsigned __int64 ulint; +#else +typedef unsigned long int ulint; +#endif /* _WIN64 */ +#endif + /********************************************************************//** Initializes the data structures used by ut_crc32*(). Does not do any diff --git a/mysys/ut0crc32.cc b/mysys/ut0crc32.cc index 0bfdcef..fce83a8 100644 --- a/mysys/ut0crc32.cc +++ b/mysys/ut0crc32.cc @@ -88,9 +88,42 @@ mysys/my_perf.c, contributed by Facebook under the following license. #include #endif /* defined(__linux__) && defined(__powerpc__) */ -#include "univ.i" #include "ut0crc32.h" +#ifndef UINT32PF +#ifdef _WIN32 +typedef unsigned __int64 ib_uint64_t; +typedef unsigned __int32 ib_uint32_t; +#else +typedef uint64_t ib_uint64_t; +typedef uint32_t ib_uint32_t; +#endif /* _WIN32 */ +#endif /* UINT32PF */ + +/* previously from ut0dbg.h */ +#ifdef UNIV_INNOCHECKSUM +#include +#define ut_a assert +#define ut_ad assert +#define ut_error assert(0) +#else /* !UNIV_INNOCHECKSUM */ +#define ut_a(EXPR) +#define ut_ad(EXPR) +#define ut_error +#endif + +#ifndef UNIV_INLINE +#ifndef UNIV_MUST_NOT_INLINE +/* Definition for inline version */ +#define UNIV_INLINE static inline +#else /* !UNIV_MUST_NOT_INLINE */ +/* If we want to compile a noninlined version we use the following macro + * definitions: */ +#define UNIV_NONINL +#define UNIV_INLINE +#endif /* !UNIV_MUST_NOT_INLINE */ +#endif /* !UNIV_INLINE */ + /** Pointer to CRC32 calculation function. */ ut_crc32_func_t ut_crc32; From 6b47c306d2cee34830d40183bc9b305ab274bc9a Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Mon, 21 Dec 2015 12:00:49 +1100 Subject: [PATCH 7/8] Replace binary_log::checksum_crc32 with optimized ut0crc32 version This preserves the same api as zlib's crc32 *_ex(tended) crc32 functions added to handle incremental crc32 calculations. Static initializer Log_event::_init LogEvent::_initializer; added to ensure client programs that use LogEvent have crc32 initialized. mysqlbinlog and mysqld's binlog code now uses optimized crc32 code rather than zlib's. Solves: Bug#79325 optimized crc32 for binary log checksums --- include/ut0crc32.h | 8 +++++ libbinlogevents/include/binlog_event.h | 19 ----------- libbinlogevents/src/binlog_event.cpp | 7 ++-- mysys/CMakeLists.txt | 2 +- mysys/ut0crc32.cc | 61 ++++++++++++++++++++++++++++++---- sql/binlog.cc | 1 - sql/log_event.cc | 5 +++ sql/log_event.h | 9 ++++- sql/rpl_binlog_sender.cc | 2 +- sql/rpl_slave.cc | 2 +- sql/rpl_utility.cc | 3 +- sql/sql_table.cc | 2 +- 12 files changed, 85 insertions(+), 36 deletions(-) diff --git a/include/ut0crc32.h b/include/ut0crc32.h index b7f6942..097787e 100644 --- a/include/ut0crc32.h +++ b/include/ut0crc32.h @@ -64,6 +64,14 @@ typedef uint32_t (*ut_crc32_func_t)(const byte* ptr, ulint len); /** Pointer to CRC32 calculation function. */ extern ut_crc32_func_t ut_crc32; +/********************************************************************//** +Appends CRC32 onto intial value. +This mirrors the zlib crc32 interface +@param crc - initial crc32 value +@param ptr - data over which to calculate CRC32. ptr==NULL to initialize +@param len - data length in bytes. */ +uint32_t checksum_crc32(uint32_t crc, const byte* ptr, ulint len); + /** 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; 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..bcf48b5 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 @@ -255,9 +256,9 @@ bool Log_event_footer::event_checksum_test(unsigned char *event_buf, 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= checksum_crc32(computed, + (const unsigned char*) event_buf, + event_len - BINLOG_CHECKSUM_LEN); if (flags != 0) { diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt index ceda2c1..8d0b036 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(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le") enable_language(ASM) diff --git a/mysys/ut0crc32.cc b/mysys/ut0crc32.cc index fce83a8..0343fdd 100644 --- a/mysys/ut0crc32.cc +++ b/mysys/ut0crc32.cc @@ -127,6 +127,9 @@ typedef uint32_t ib_uint32_t; /** Pointer to CRC32 calculation function. */ ut_crc32_func_t ut_crc32; +/** Pointer to CRC32 function which takes additional crc arg */ +uint32_t (*ut_crc32_ex)(const byte* ptr, ulint len, uint32_t crc); + /** Text description of CRC32 implementation */ const char *ut_crc32_implementation = NULL; @@ -300,11 +303,13 @@ ut_crc32_64_legacy_big_endian_hw( @param[in] len data length @return CRC-32C (polynomial 0x11EDC6F41) */ uint32_t -ut_crc32_hw( +ut_crc32_hw_ex( const byte* buf, - ulint len) + ulint len, + uint32_t crc +) { - uint32_t crc = 0xFFFFFFFFU; + crc ^= 0xFFFFFFFFU; /* Calculate byte-by-byte up to an 8-byte aligned address. After this consume the input 8-bytes at a time. */ @@ -382,6 +387,15 @@ ut_crc32_hw( return(~crc); } +uint32_t +ut_crc32_hw( + const byte* buf, + ulint len +) +{ + return ut_crc32_hw_ex(buf, len, 0U); +} + /** Calculates CRC32 using hardware/CPU instructions. This function uses big endian byte ordering when converting byte sequence to integers. @@ -482,6 +496,23 @@ ut_crc32_power8( #endif /* __powerpc__ */ } +UNIV_INLINE +ib_uint32_t +ut_crc32_power8_ex( +/*===========*/ + const byte* buf, /*!< in: data over which to calculate CRC32 */ + ulint len, /*!< in: data length */ + ib_uint32_t crc=0U) /*!< in: intial crc */ +{ +#if defined(__powerpc__) + return crc32_vpmsum(crc, buf, len); +#else + ut_error; + /* silence compiler warning about unused parameters */ + return((ib_uint32_t) buf[len]); +#endif /* __powerpc__ */ +} + /********************************************************************//** Initializes the table that is used to generate the CRC32 if the CPU does not have support for it. */ @@ -616,11 +647,12 @@ ut_crc32_64_legacy_big_endian_sw( @param[in] len data length @return CRC-32C (polynomial 0x11EDC6F41) */ uint32_t -ut_crc32_sw( +ut_crc32_sw_ex( const byte* buf, - ulint len) + ulint len, + uint32_t crc) { - uint32_t crc = 0xFFFFFFFFU; + crc ^= 0xFFFFFFFFU; ut_a(ut_crc32_slice8_table_initialized); @@ -661,6 +693,14 @@ ut_crc32_sw( return(~crc); } +uint32_t +ut_crc32_sw( + const byte* buf, + ulint len) +{ + return ut_crc32_sw_ex(buf, len, 0x0U); +} + /** Calculates CRC32 in software, without using CPU instructions. This function uses big endian byte ordering when converting byte sequence to integers. @@ -776,6 +816,7 @@ ut_crc32_init() if (ut_crc32_sse2_enabled) { ut_crc32 = ut_crc32_hw; + ut_crc32_ex = ut_crc32_hw_ex; ut_crc32_legacy_big_endian = ut_crc32_legacy_big_endian_hw; ut_crc32_byte_by_byte = ut_crc32_byte_by_byte_hw; ut_crc32_implementation = "SSE2 crc32 instructions"; @@ -787,6 +828,7 @@ ut_crc32_init() if (getauxval(AT_HWCAP2) & PPC_FEATURE2_ARCH_2_07) { ut_crc32_implementation = "POWER8 crc32 instructions"; ut_crc32 = ut_crc32_power8; + ut_crc32_ex = ut_crc32_power8_ex; ut_crc32_legacy_big_endian = ut_crc32_legacy_big_endian_sw; ut_crc32_byte_by_byte = ut_crc32_byte_by_byte_sw; /* needed for ut_crc32_legacy_big_endian_sw */ @@ -796,8 +838,15 @@ ut_crc32_init() if (!ut_crc32_sse2_enabled) { ut_crc32_slice8_table_init(); ut_crc32 = ut_crc32_sw; + ut_crc32_ex = ut_crc32_sw_ex; ut_crc32_legacy_big_endian = ut_crc32_legacy_big_endian_sw; ut_crc32_byte_by_byte = ut_crc32_byte_by_byte_sw; ut_crc32_implementation = "Software implemented crc32"; } } + +uint32_t checksum_crc32(uint32_t crc, const byte* ptr, ulint len) +{ + if (ptr == NULL) return 0x0U; + return ut_crc32_ex(ptr, len, crc); +} diff --git a/sql/binlog.cc b/sql/binlog.cc index cc2d613..e1d8a64 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 df0c0ac..f844d88 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() 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..abbbc74 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; diff --git a/sql/rpl_slave.cc b/sql/rpl_slave.cc index 991e57f..774c141 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" ":"") diff --git a/sql/rpl_utility.cc b/sql/rpl_utility.cc index f4c8f2e..2980c6a 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" // checksum_crv32 #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 diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 816a5a1..df34391 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)) From d0ebe000dfbf8b927bd97e0787167145061bf36e Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Mon, 21 Dec 2015 12:53:05 +1100 Subject: [PATCH 8/8] use optimized crc32 function for SQL crc32 function Solves: Bug#79155 optimized crc32 for CRC32() 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 eaa6d85..1ae80cb 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -43,6 +43,7 @@ #include "password.h" // my_make_scrambled_password #include "sql_class.h" // THD #include "strfunc.h" // hexchar_to_int +#include "ut0crc32.h" // checksum_crc32 C_MODE_START #include "../mysys/my_static.h" // For soundex_map @@ -4892,7 +4893,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) checksum_crc32(0L, (uchar*)res->ptr(), res->length()); } #ifdef HAVE_COMPRESS