Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1# Copyright (c) 2023-present The Bitcoin Core developers2# Distributed under the MIT software license, see the accompanying3# file COPYING or https://opensource.org/license/mit/.5# This file is part of the transition from Autotools to CMake. Once CMake6# support has been merged we should switch to using the upstream CMake7# buildsystem.9include(CheckCXXSourceCompiles)10include(CheckSourceCompilesWithFlags)12# Check for __builtin_prefetch support in the compiler.13check_cxx_source_compiles("14int main() {15char data = 0;16const char* address = &data;17__builtin_prefetch(address, 0, 0);18return 0;19}20" HAVE_BUILTIN_PREFETCH21)23# Check for _mm_prefetch support in the compiler.24check_cxx_source_compiles("25#if defined(_MSC_VER)26#include <intrin.h>27#else28#include <xmmintrin.h>29#endif31int main() {32char data = 0;33const char* address = &data;34_mm_prefetch(address, _MM_HINT_NTA);35return 0;36}37" HAVE_MM_PREFETCH38)40# Check for SSE4.2 support in the compiler.41if(MSVC)42set(SSE42_CXXFLAGS /arch:AVX)43else()44set(SSE42_CXXFLAGS -msse4.2)45endif()46check_cxx_source_compiles_with_flags("47#include <cstdint>48#if defined(_MSC_VER)49#include <intrin.h>50#elif defined(__GNUC__) && defined(__SSE4_2__)51#include <nmmintrin.h>52#endif54int main() {55uint64_t l = 0;56l = _mm_crc32_u8(l, 0);57l = _mm_crc32_u32(l, 0);58l = _mm_crc32_u64(l, 0);59return l;60}61" HAVE_SSE4262CXXFLAGS ${SSE42_CXXFLAGS}63)65# Check for ARMv8 w/ CRC and CRYPTO extensions support in the compiler.66set(ARM64_CRC_CXXFLAGS -march=armv8-a+crc+crypto)67check_cxx_source_compiles_with_flags("68#include <arm_acle.h>69#include <arm_neon.h>71int main() {72#ifdef __aarch64__73__crc32cb(0, 0); __crc32ch(0, 0); __crc32cw(0, 0); __crc32cd(0, 0);74vmull_p64(0, 0);75#else76#error crc32c library does not support hardware acceleration on 32-bit ARM77#endif78return 0;79}80" HAVE_ARM64_CRC32C81CXXFLAGS ${ARM64_CRC_CXXFLAGS}82)84add_library(crc32c STATIC EXCLUDE_FROM_ALL85${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c.cc86${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c_portable.cc87)88target_compile_definitions(crc32c PRIVATE89HAVE_BUILTIN_PREFETCH=$<BOOL:${HAVE_BUILTIN_PREFETCH}>90HAVE_MM_PREFETCH=$<BOOL:${HAVE_MM_PREFETCH}>91HAVE_STRONG_GETAUXVAL=$<BOOL:${HAVE_STRONG_GETAUXVAL}>92BYTE_ORDER_BIG_ENDIAN=$<STREQUAL:${CMAKE_CXX_BYTE_ORDER},BIG_ENDIAN>93HAVE_SSE42=$<BOOL:${HAVE_SSE42}>94HAVE_ARM64_CRC32C=$<BOOL:${HAVE_ARM64_CRC32C}>95)96target_include_directories(crc32c97PUBLIC98$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/crc32c/include>99)100target_link_libraries(crc32c PRIVATE core_interface)101set_target_properties(crc32c PROPERTIES EXPORT_COMPILE_COMMANDS OFF)103if(HAVE_SSE42)104set(_crc32_src ${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c_sse42.cc)105target_sources(crc32c PRIVATE ${_crc32_src})106set_property(SOURCE ${_crc32_src} PROPERTY COMPILE_OPTIONS ${SSE42_CXXFLAGS})107endif()109if(HAVE_ARM64_CRC32C)110set(_crc32_src ${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c_arm64.cc)111target_sources(crc32c PRIVATE ${_crc32_src})112set_property(SOURCE ${_crc32_src} PROPERTY COMPILE_OPTIONS ${ARM64_CRC_CXXFLAGS})113endif()115unset(_crc32_src)
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.