Fix compilation on Apple Silicon (#7714)

Summary:
Closes - https://github.com/facebook/rocksdb/issues/7710

I tested this on an Apple DTK (Developer Transition Kit) with an Apple A12Z Bionic CPU and macOS Big Sur (11.0.1).

Previously the arm64 specific CRC optimisations were limited to Linux only OS... Well now Apple Silicon is also arm64 but runs macOS ;-)

Pull Request resolved: https://github.com/facebook/rocksdb/pull/7714

Reviewed By: ltamasi

Differential Revision: D25287349

Pulled By: pdillinger

fbshipit-source-id: 639b168bf0ac2652907531e9604936ac4974b577
This commit is contained in:
Adam Retter 2020-12-04 15:21:18 -08:00 committed by Facebook GitHub Bot
parent eb5a8c06dd
commit ee4bd4780b
3 changed files with 12 additions and 8 deletions

View File

@ -41,7 +41,7 @@
#endif #endif
#if defined(__linux__) && defined(HAVE_ARM64_CRC) #if defined(HAVE_ARM64_CRC)
bool pmull_runtime_flag = false; bool pmull_runtime_flag = false;
#endif #endif
@ -478,7 +478,7 @@ static bool isAltiVec() {
} }
#endif #endif
#if defined(__linux__) && defined(HAVE_ARM64_CRC) #if defined(HAVE_ARM64_CRC)
uint32_t ExtendARMImpl(uint32_t crc, const char *buf, size_t size) { uint32_t ExtendARMImpl(uint32_t crc, const char *buf, size_t size) {
return crc32c_arm64(crc, (const unsigned char *)buf, size); return crc32c_arm64(crc, (const unsigned char *)buf, size);
} }
@ -498,7 +498,7 @@ std::string IsFastCrc32Supported() {
has_fast_crc = false; has_fast_crc = false;
arch = "PPC"; arch = "PPC";
#endif #endif
#elif defined(__linux__) && defined(HAVE_ARM64_CRC) #elif defined(HAVE_ARM64_CRC)
if (crc32c_runtime_check()) { if (crc32c_runtime_check()) {
has_fast_crc = true; has_fast_crc = true;
arch = "Arm64"; arch = "Arm64";
@ -1231,7 +1231,7 @@ uint32_t crc32c_3way(uint32_t crc, const char* buf, size_t len) {
static inline Function Choose_Extend() { static inline Function Choose_Extend() {
#ifdef HAVE_POWER8 #ifdef HAVE_POWER8
return isAltiVec() ? ExtendPPCImpl : ExtendImpl<Slow_CRC32>; return isAltiVec() ? ExtendPPCImpl : ExtendImpl<Slow_CRC32>;
#elif defined(__linux__) && defined(HAVE_ARM64_CRC) #elif defined(HAVE_ARM64_CRC)
if(crc32c_runtime_check()) { if(crc32c_runtime_check()) {
pmull_runtime_flag = crc32c_pmull_runtime_check(); pmull_runtime_flag = crc32c_pmull_runtime_check();
return ExtendARMImpl; return ExtendARMImpl;

View File

@ -5,9 +5,11 @@
#include "util/crc32c_arm64.h" #include "util/crc32c_arm64.h"
#if defined(__linux__) && defined(HAVE_ARM64_CRC) #if defined(HAVE_ARM64_CRC)
#if defined(__linux__)
#include <asm/hwcap.h> #include <asm/hwcap.h>
#endif
#ifdef ROCKSDB_AUXV_GETAUXVAL_PRESENT #ifdef ROCKSDB_AUXV_GETAUXVAL_PRESENT
#include <sys/auxv.h> #include <sys/auxv.h>
#endif #endif
@ -65,8 +67,8 @@ __attribute__((__no_sanitize__("alignment")))
__attribute__((__no_sanitize_undefined__)) __attribute__((__no_sanitize_undefined__))
#endif #endif
#endif #endif
uint32_t crc32c_arm64(uint32_t crc, unsigned char const *data, uint32_t
unsigned len) { crc32c_arm64(uint32_t crc, unsigned char const *data, size_t len) {
const uint8_t *buf8; const uint8_t *buf8;
const uint64_t *buf64 = (uint64_t *)data; const uint64_t *buf64 = (uint64_t *)data;
int length = (int)len; int length = (int)len;

View File

@ -7,6 +7,7 @@
#define UTIL_CRC32C_ARM64_H #define UTIL_CRC32C_ARM64_H
#include <cinttypes> #include <cinttypes>
#include <cstddef>
#if defined(__aarch64__) || defined(__AARCH64__) #if defined(__aarch64__) || defined(__AARCH64__)
@ -33,7 +34,8 @@
PREF4X64L1(buffer, (PREF_OFFSET), 8) \ PREF4X64L1(buffer, (PREF_OFFSET), 8) \
PREF4X64L1(buffer, (PREF_OFFSET), 12) PREF4X64L1(buffer, (PREF_OFFSET), 12)
extern uint32_t crc32c_arm64(uint32_t crc, unsigned char const *data, unsigned len); extern uint32_t crc32c_arm64(uint32_t crc, unsigned char const *data,
size_t len);
extern uint32_t crc32c_runtime_check(void); extern uint32_t crc32c_runtime_check(void);
extern bool crc32c_pmull_runtime_check(void); extern bool crc32c_pmull_runtime_check(void);