Skip to content

Commit

Permalink
Squashed 'src/crc32c/' changes from 224988680f..0bac72c455
Browse files Browse the repository at this point in the history
0bac72c455 Merge bitcoin-core/crc32c-subtree#5: local, bugfix: Define `CRC32C_HAVE_CONFIG_H` macro for all targets
002cfa280e local, bugfix: Define `CRC32C_HAVE_CONFIG_H` macro for all targets
0d624261ef Merge bitcoin-core/crc32c-subtree#2: Merge upstream
cac7ca830b Merge commit 'fa5ade41ee480003d9c5af6f43567ba22e4e17e6' into bitcoin-fork
fa5ade41ee Fix compilation warnings on ARM64 with old GCC versions. (dogecoin#52)
db08d22129 Updated Travis-CI configuration. (dogecoin#51)
e31619a5b7 Fix GitHub links. (dogecoin#50)
7fa4c263e8 Update Travis CI config. (dogecoin#49)
a3d9e6d1a4 Updated third_party/ and Travis CI config. (dogecoin#48)
b5ef9be675 Merge #1: Merge changes from upstream
9e7f512430 Merge remote-tracking branch 'origin/master' into bitcoin-fork
1f85030246 Add support for ARM64 darwin (dogecoin#43)
3bb959c982 Remove unnecessary reinterpret_cast (dogecoin#42)
2e97ab26b1 Fix (unused) ReadUint64LE for BE machines (dogecoin#41)
47b40d2209 Bump dependencies. (dogecoin#40)
ba74185625 Move CI to Visual Studio 2019.
efa301a7e5 Allow different C/C++ standards when this is used as a subproject.
cc6d71465e CMake: Use configure_package_config_file()

git-subtree-dir: src/crc32c
git-subtree-split: 0bac72c4552baf1cc9fe03ee30d6542cb7af2e04
  • Loading branch information
patricklodder committed Nov 24, 2023
1 parent 2e18193 commit e16843d
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 77 deletions.
13 changes: 7 additions & 6 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ environment:
matrix:
# AppVeyor currently has no custom job name feature.
# http://help.appveyor.com/discussions/questions/1623-can-i-provide-a-friendly-name-for-jobs
- JOB: Visual Studio 2017
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_GENERATOR: Visual Studio 15 2017
- JOB: Visual Studio 2019
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
CMAKE_GENERATOR: Visual Studio 16 2019

platform:
- x86
Expand All @@ -24,10 +24,11 @@ build_script:
- git submodule update --init --recursive
- mkdir build
- cd build
- if "%platform%"=="x64" set CMAKE_GENERATOR=%CMAKE_GENERATOR% Win64
- if "%platform%"=="x86" (set CMAKE_GENERATOR_PLATFORM="Win32")
else (set CMAKE_GENERATOR_PLATFORM="%platform%")
- cmake --version
- cmake .. -G "%CMAKE_GENERATOR%" -DCRC32C_USE_GLOG=0
-DCMAKE_CONFIGURATION_TYPES="%CONFIGURATION%"
- cmake .. -G "%CMAKE_GENERATOR%" -A "%CMAKE_GENERATOR_PLATFORM%"
-DCMAKE_CONFIGURATION_TYPES="%CONFIGURATION%" -DCRC32C_USE_GLOG=0
- cmake --build . --config "%CONFIGURATION%"
- cd ..

Expand Down
18 changes: 9 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

language: cpp
dist: bionic
osx_image: xcode10.3
osx_image: xcode12.5

compiler:
- gcc
Expand All @@ -24,20 +24,20 @@ env:
addons:
apt:
sources:
- sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main'
- sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-12 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages:
- clang-9
- clang-12
- cmake
- gcc-9
- g++-9
- gcc-11
- g++-11
- ninja-build
homebrew:
packages:
- cmake
- gcc@9
- llvm@9
- gcc@11
- llvm@12
- ninja
update: true

Expand All @@ -48,14 +48,14 @@ install:
export PATH="$(brew --prefix llvm)/bin:$PATH";
fi
# /usr/bin/gcc points to an older compiler on both Linux and macOS.
- if [ "$CXX" = "g++" ]; then export CXX="g++-9" CC="gcc-9"; fi
- if [ "$CXX" = "g++" ]; then export CXX="g++-11" CC="gcc-11"; fi
# /usr/bin/clang points to an older compiler on both Linux and macOS.
#
# Homebrew's llvm package doesn't ship a versioned clang++ binary, so the values
# below don't work on macOS. Fortunately, the path change above makes the
# default values (clang and clang++) resolve to the correct compiler on macOS.
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then
if [ "$CXX" = "clang++" ]; then export CXX="clang++-9" CC="clang-9"; fi;
if [ "$CXX" = "clang++" ]; then export CXX="clang++-12" CC="clang-12"; fi;
fi
- echo ${CC}
- echo ${CXX}
Expand Down
4 changes: 2 additions & 2 deletions .ycm_extra_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"""YouCompleteMe configuration that interprets a .clang_complete file.
This module implementes the YouCompleteMe configuration API documented at:
https://github.com/Valloric/ycmd#ycm_extra_confpy-specification
https://github.com/ycm-core/ycmd#ycm_extra_confpy-specification
The implementation loads and processes a .clang_complete file, documented at:
https://github.com/Rip-Rip/clang_complete/blob/master/README.md
https://github.com/xavierd/clang_complete/blob/master/README.md
"""

import os
Expand Down
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ Google Inc.

Fangming Fang <Fangming.Fang@arm.com>
Vadim Skipin <vadim.skipin@gmail.com>
Rodrigo Tobar <rtobar@icrar.org>
Harry Mallon <hjmallon@gmail.com>
50 changes: 31 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@
cmake_minimum_required(VERSION 3.1)
project(Crc32c VERSION 1.1.0 LANGUAGES C CXX)

# This project can use C11, but will gracefully decay down to C89.
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED OFF)
set(CMAKE_C_EXTENSIONS OFF)

# This project requires C++11.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# C standard can be overridden when this is used as a sub-project.
if(NOT CMAKE_C_STANDARD)
# This project can use C11, but will gracefully decay down to C89.
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED OFF)
set(CMAKE_C_EXTENSIONS OFF)
endif(NOT CMAKE_C_STANDARD)

# C++ standard can be overridden when this is used as a sub-project.
if(NOT CMAKE_CXX_STANDARD)
# This project requires C++11.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif(NOT CMAKE_CXX_STANDARD)

# https://github.com/izenecloud/cmake/blob/master/SetCompilerWarningAll.cmake
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
Expand Down Expand Up @@ -269,7 +275,7 @@ target_sources(crc32c
PRIVATE
"${PROJECT_BINARY_DIR}/include/crc32c/crc32c_config.h"
"src/crc32c_arm64.h"
"src/crc32c_arm64_linux_check.h"
"src/crc32c_arm64_check.h"
"src/crc32c_internal.h"
"src/crc32c_portable.cc"
"src/crc32c_prefetch.h"
Expand All @@ -290,9 +296,10 @@ target_include_directories(crc32c
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

target_compile_definitions(crc32c
PRIVATE
CRC32C_HAVE_CONFIG_H=1
set_property(
TARGET crc32c_arm64 crc32c_sse42 crc32c
APPEND
PROPERTY COMPILE_DEFINITIONS CRC32C_HAVE_CONFIG_H
)

set_target_properties(crc32c
Expand Down Expand Up @@ -405,19 +412,24 @@ if(CRC32C_INSTALL)
)

include(CMakePackageConfigHelpers)
configure_package_config_file(
"${PROJECT_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/Crc32cConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
)
install(
EXPORT Crc32cTargets
NAMESPACE Crc32c::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Crc32c"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
install(
FILES
"Crc32cConfig.cmake"
"${PROJECT_BINARY_DIR}/Crc32cConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Crc32c"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
endif(CRC32C_INSTALL)
4 changes: 4 additions & 0 deletions Crc32cConfig.cmake → Crc32cConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. See the AUTHORS file for names of contributors.

@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/Crc32cTargets.cmake")

check_required_components(Crc32c)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ apm install autocomplete-clang build build-cmake clang-format language-cmake \

If you don't mind more setup in return for more speed, replace
`autocomplete-clang` and `linter-clang` with `you-complete-me`. This requires
[setting up ycmd](https://github.com/Valloric/ycmd#building).
[setting up ycmd](https://github.com/ycm-core/ycmd#building).

```bash
apm install autocomplete-plus build build-cmake clang-format language-cmake \
Expand Down
6 changes: 3 additions & 3 deletions src/crc32c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <cstdint>

#include "./crc32c_arm64.h"
#include "./crc32c_arm64_linux_check.h"
#include "./crc32c_arm64_check.h"
#include "./crc32c_internal.h"
#include "./crc32c_sse42.h"
#include "./crc32c_sse42_check.h"
Expand All @@ -20,8 +20,8 @@ uint32_t Extend(uint32_t crc, const uint8_t* data, size_t count) {
static bool can_use_sse42 = CanUseSse42();
if (can_use_sse42) return ExtendSse42(crc, data, count);
#elif HAVE_ARM64_CRC32C
static bool can_use_arm_linux = CanUseArm64Linux();
if (can_use_arm_linux) return ExtendArm64(crc, data, count);
static bool can_use_arm64_crc32 = CanUseArm64Crc32();
if (can_use_arm64_crc32) return ExtendArm64(crc, data, count);
#endif // HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__))

return ExtendPortable(crc, data, count);
Expand Down
23 changes: 11 additions & 12 deletions src/crc32c_arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

namespace crc32c {

uint32_t ExtendArm64(uint32_t crc, const uint8_t *buf, size_t size) {
uint32_t ExtendArm64(uint32_t crc, const uint8_t *data, size_t size) {
int64_t length = size;
uint32_t crc0, crc1, crc2, crc3;
uint64_t t0, t1, t2;
Expand All @@ -74,7 +74,6 @@ uint32_t ExtendArm64(uint32_t crc, const uint8_t *buf, size_t size) {
const poly64_t k0 = 0x8d96551c, k1 = 0xbd6f81f8, k2 = 0xdcb17aa4;

crc = crc ^ kCRC32Xor;
const uint8_t *p = reinterpret_cast<const uint8_t *>(buf);

while (length >= KBYTES) {
crc0 = crc;
Expand All @@ -83,14 +82,14 @@ uint32_t ExtendArm64(uint32_t crc, const uint8_t *buf, size_t size) {
crc3 = 0;

// Process 1024 bytes in parallel.
CRC32C1024BYTES(p);
CRC32C1024BYTES(data);

// Merge the 4 partial CRC32C values.
t2 = (uint64_t)vmull_p64(crc2, k2);
t1 = (uint64_t)vmull_p64(crc1, k1);
t0 = (uint64_t)vmull_p64(crc0, k0);
crc = __crc32cd(crc3, *(uint64_t *)p);
p += sizeof(uint64_t);
crc = __crc32cd(crc3, *(uint64_t *)data);
data += sizeof(uint64_t);
crc ^= __crc32cd(0, t2);
crc ^= __crc32cd(0, t1);
crc ^= __crc32cd(0, t0);
Expand All @@ -99,23 +98,23 @@ uint32_t ExtendArm64(uint32_t crc, const uint8_t *buf, size_t size) {
}

while (length >= 8) {
crc = __crc32cd(crc, *(uint64_t *)p);
p += 8;
crc = __crc32cd(crc, *(uint64_t *)data);
data += 8;
length -= 8;
}

if (length & 4) {
crc = __crc32cw(crc, *(uint32_t *)p);
p += 4;
crc = __crc32cw(crc, *(uint32_t *)data);
data += 4;
}

if (length & 2) {
crc = __crc32ch(crc, *(uint16_t *)p);
p += 2;
crc = __crc32ch(crc, *(uint16_t *)data);
data += 2;
}

if (length & 1) {
crc = __crc32cb(crc, *p);
crc = __crc32cb(crc, *data);
}

return crc ^ kCRC32Xor;
Expand Down
8 changes: 4 additions & 4 deletions src/crc32c_arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.

// Linux-specific code checking the availability for ARM CRC32C instructions.
// ARM-specific code

#ifndef CRC32C_CRC32C_ARM_LINUX_H_
#define CRC32C_CRC32C_ARM_LINUX_H_
#ifndef CRC32C_CRC32C_ARM_H_
#define CRC32C_CRC32C_ARM_H_

#include <cstddef>
#include <cstdint>
Expand All @@ -24,4 +24,4 @@ uint32_t ExtendArm64(uint32_t crc, const uint8_t* data, size_t count);

#endif // HAVE_ARM64_CRC32C

#endif // CRC32C_CRC32C_ARM_LINUX_H_
#endif // CRC32C_CRC32C_ARM_H_
36 changes: 27 additions & 9 deletions src/crc32c_arm64_linux_check.h → src/crc32c_arm64_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.

// ARM Linux-specific code checking for the availability of CRC32C instructions.
// ARM-specific code checking for the availability of CRC32C instructions.

#ifndef CRC32C_CRC32C_ARM_LINUX_CHECK_H_
#define CRC32C_CRC32C_ARM_LINUX_CHECK_H_

// X86-specific code checking for the availability of SSE4.2 instructions.
#ifndef CRC32C_CRC32C_ARM_CHECK_H_
#define CRC32C_CRC32C_ARM_CHECK_H_

#include <cstddef>
#include <cstdint>
Expand All @@ -18,6 +16,7 @@

#if HAVE_ARM64_CRC32C

#ifdef __linux__
#if HAVE_STRONG_GETAUXVAL
#include <sys/auxv.h>
#elif HAVE_WEAK_GETAUXVAL
Expand All @@ -27,17 +26,36 @@ extern "C" unsigned long getauxval(unsigned long type) __attribute__((weak));

#define AT_HWCAP 16
#endif // HAVE_STRONG_GETAUXVAL || HAVE_WEAK_GETAUXVAL
#endif // defined (__linux__)

#ifdef __APPLE__
#include <sys/types.h>
#include <sys/sysctl.h>
#endif // defined (__APPLE__)

namespace crc32c {

inline bool CanUseArm64Linux() {
#if HAVE_STRONG_GETAUXVAL || HAVE_WEAK_GETAUXVAL
inline bool CanUseArm64Crc32() {
#if defined (__linux__) && (HAVE_STRONG_GETAUXVAL || HAVE_WEAK_GETAUXVAL)
// From 'arch/arm64/include/uapi/asm/hwcap.h' in Linux kernel source code.
constexpr unsigned long kHWCAP_PMULL = 1 << 4;
constexpr unsigned long kHWCAP_CRC32 = 1 << 7;
unsigned long hwcap = (&getauxval != nullptr) ? getauxval(AT_HWCAP) : 0;
unsigned long hwcap =
#if HAVE_STRONG_GETAUXVAL
// Some compilers warn on (&getauxval != nullptr) in the block below.
getauxval(AT_HWCAP);
#elif HAVE_WEAK_GETAUXVAL
(&getauxval != nullptr) ? getauxval(AT_HWCAP) : 0;
#else
#error This is supposed to be nested inside a check for HAVE_*_GETAUXVAL.
#endif // HAVE_STRONG_GETAUXVAL
return (hwcap & (kHWCAP_PMULL | kHWCAP_CRC32)) ==
(kHWCAP_PMULL | kHWCAP_CRC32);
#elif defined(__APPLE__)
int val = 0;
size_t len = sizeof(val);
return sysctlbyname("hw.optional.armv8_crc32", &val, &len, nullptr, 0) == 0
&& val != 0;
#else
return false;
#endif // HAVE_STRONG_GETAUXVAL || HAVE_WEAK_GETAUXVAL
Expand All @@ -47,4 +65,4 @@ inline bool CanUseArm64Linux() {

#endif // HAVE_ARM64_CRC32C

#endif // CRC32C_CRC32C_ARM_LINUX_CHECK_H_
#endif // CRC32C_CRC32C_ARM_CHECK_H_
Loading

0 comments on commit e16843d

Please sign in to comment.