Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ endif

CXXFLAGS += $(ARCHFLAG)

ifeq (,$(shell $(CXX) -fsyntax-only -march=armv8-a+crc+crypto -xc /dev/null 2>&1))
# compile aarch64 CRC and pmull (in the aes set) instructions: Linux aarch64 default excludes them
ifeq (,$(shell $(CXX) -fsyntax-only -march=armv8-a+crc+aes -xc /dev/null 2>&1))
ifneq ($(PLATFORM),OS_MACOSX)
CXXFLAGS += -march=armv8-a+crc+crypto
CFLAGS += -march=armv8-a+crc+crypto
ARMCRC_SOURCE=1
CXXFLAGS += -march=armv8-a+crc+aes
CFLAGS += -march=armv8-a+crc+aes
endif
endif

Expand Down
24 changes: 12 additions & 12 deletions util/crc32c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ASSERT_FEATURE_COMPAT_HEADER();
#include <wmmintrin.h>
#endif

#if defined(HAVE_ARM64_CRC)
#if defined(__ARM_FEATURE_CRC32)
bool pmull_runtime_flag = false;
#endif

Expand Down Expand Up @@ -353,7 +353,7 @@ static bool isAltiVec() {
}
#endif

#if defined(HAVE_ARM64_CRC)
#if defined(__ARM_FEATURE_CRC32)
uint32_t ExtendARMImpl(uint32_t crc, const char* buf, size_t size) {
return crc32c_arm64(crc, (const unsigned char*)buf, size);
}
Expand All @@ -362,30 +362,30 @@ uint32_t ExtendARMImpl(uint32_t crc, const char* buf, size_t size) {
std::string IsFastCrc32Supported() {
bool has_fast_crc = false;
std::string fast_zero_msg;
std::string arch;
std::string arch = "unknown_architecture";
#ifdef HAVE_POWER8
arch = "PPC";
#ifdef HAS_ALTIVEC
if (arch_ppc_probe()) {
has_fast_crc = true;
arch = "PPC";
}
#else
has_fast_crc = false;
arch = "PPC";
#endif
#elif defined(HAVE_ARM64_CRC)
#elif defined(__aarch64__) || defined(_M_ARM64)
arch = "Arm64";
#if defined(__ARM_FEATURE_CRC32)
if (crc32c_runtime_check()) {
has_fast_crc = true;
arch = "Arm64";
pmull_runtime_flag = crc32c_pmull_runtime_check();
} else {
has_fast_crc = false;
arch = "Arm64";
}
#else
#ifdef __SSE4_2__
#endif
#elif defined(__SSE4_2__)
has_fast_crc = true;
#endif // __SSE4_2__
arch = "x86";
#elif defined(__x86_64__) || defined(_M_X64)
arch = "x86";
#endif
if (has_fast_crc) {
Expand Down Expand Up @@ -1106,7 +1106,7 @@ uint32_t crc32c_3way(uint32_t crc, const char* buf, size_t len) {
static inline Function Choose_Extend() {
#ifdef HAVE_POWER8
return isAltiVec() ? ExtendPPCImpl : ExtendImpl<DefaultCRC32>;
#elif defined(HAVE_ARM64_CRC)
#elif defined(__ARM_FEATURE_CRC32)
if(crc32c_runtime_check()) {
pmull_runtime_flag = crc32c_pmull_runtime_check();
return ExtendARMImpl;
Expand Down
8 changes: 4 additions & 4 deletions util/crc32c_arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "util/crc32c_arm64.h"

#if defined(HAVE_ARM64_CRC)
#if defined(__ARM_FEATURE_CRC32)

#if defined(__linux__)
#include <asm/hwcap.h>
Expand All @@ -29,7 +29,7 @@
#include <sys/types.h>
#endif

#ifdef HAVE_ARM64_CRYPTO
#ifdef __ARM_FEATURE_CRC32
/* unfolding to compute 8 * 3 = 24 bytes parallelly */
#define CRC32C24BYTES(ITR) \
crc1 = crc32c_u64(crc1, *(buf64 + BLK_LENGTH + (ITR))); \
Expand Down Expand Up @@ -126,8 +126,8 @@ crc32c_arm64(uint32_t crc, unsigned char const *data, size_t len) {
* Skip Crc32c Parallel computation if no crypto extension available.
*/
if (pmull_runtime_flag) {
/* Macro (HAVE_ARM64_CRYPTO) is used for compiling check */
#ifdef HAVE_ARM64_CRYPTO
/* Macro __ARM_FEATURE_AES is required to support pmull instruction */
#ifdef __ARM_FEATURE_AES
/* Crc32c Parallel computation
* Algorithm comes from Intel whitepaper:
* crc-iscsi-polynomial-crc32-instruction-paper
Expand Down
6 changes: 2 additions & 4 deletions util/crc32c_arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#if defined(__aarch64__) || defined(__AARCH64__)

#ifdef __ARM_FEATURE_CRC32
#define HAVE_ARM64_CRC
#include <arm_acle.h>
#define crc32c_u8(crc, v) __crc32cb(crc, v)
#define crc32c_u16(crc, v) __crc32ch(crc, v)
Expand Down Expand Up @@ -40,10 +39,9 @@ uint32_t crc32c_arm64(uint32_t crc, unsigned char const *data, size_t len);
uint32_t crc32c_runtime_check(void);
bool crc32c_pmull_runtime_check(void);

#ifdef __ARM_FEATURE_CRYPTO
#define HAVE_ARM64_CRYPTO
#ifdef __ARM_FEATURE_AES
#include <arm_neon.h>
#endif // __ARM_FEATURE_CRYPTO
#endif // __ARM_FEATURE_AES
#endif // __ARM_FEATURE_CRC32

#endif // defined(__aarch64__) || defined(__AARCH64__)
Expand Down
32 changes: 32 additions & 0 deletions util/crc32c_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,38 @@ TEST(CRC, Crc32cCombineBigSizeTest) {
ASSERT_EQ(crc1_2, crc1_2_combine);
}

TEST(CRC, IsFastCrc32Supported) {
std::string output = IsFastCrc32Supported();

std::string test_detected_arch = "TODO: add arch defines to test";
bool test_fast_crc_supported = false;

#if defined(__x86_64__) || defined(_M_X64)
test_detected_arch = "x86";

#if defined(__SSE4_2__)
test_fast_crc_supported = true;
#endif

#elif defined(__aarch64__) || defined(_M_ARM64)
test_detected_arch = "Arm64";

#ifdef __ARM_FEATURE_CRC32
test_fast_crc_supported = true;
#endif

#endif

std::string supported_string = "Not supported";
if (test_fast_crc_supported) {
supported_string = "Supported";
}
std::string expected = supported_string = " on " + test_detected_arch;

ASSERT_NE(output.find(expected), std::string::npos)
<< "expected=" << expected << "output=" << output;
}

} // namespace ROCKSDB_NAMESPACE::crc32c

// copied from folly
Expand Down
Loading