Skip to content

Commit

Permalink
Merge PR: build rocksdb on m1 (#1416)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongqiuwood authored Jan 11, 2022
1 parent eed2925 commit 233ad87
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 3 deletions.
103 changes: 103 additions & 0 deletions libs/rocksdb/arm64_crc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
diff --git a/util/crc32c.cc b/util/crc32c.cc
index 959658099..74ce80b36 100644
--- a/util/crc32c.cc
+++ b/util/crc32c.cc
@@ -41,7 +41,7 @@

#endif

-#if defined(__linux__) && defined(HAVE_ARM64_CRC)
+#if defined(HAVE_ARM64_CRC)
bool pmull_runtime_flag = false;
#endif

@@ -346,6 +346,7 @@ static inline void Slow_CRC32(uint64_t* l, uint8_t const **p) {
table0_[c >> 24];
}

+#if defined HAVE_SSE42 && defined NO_THREEWAY_CRC32C
static inline void Fast_CRC32(uint64_t* l, uint8_t const **p) {
#ifndef HAVE_SSE42
Slow_CRC32(l, p);
@@ -359,6 +360,7 @@ static inline void Fast_CRC32(uint64_t* l, uint8_t const **p) {
*p += 4;
#endif
}
+#endif

template<void (*CRC32)(uint64_t*, uint8_t const**)>
uint32_t ExtendImpl(uint32_t crc, const char* buf, size_t size) {
@@ -474,7 +476,7 @@ static bool isAltiVec() {
}
#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) {
return crc32c_arm64(crc, (const unsigned char *)buf, size);
}
@@ -494,7 +496,7 @@ std::string IsFastCrc32Supported() {
has_fast_crc = false;
arch = "PPC";
#endif
-#elif defined(__linux__) && defined(HAVE_ARM64_CRC)
+#elif defined(HAVE_ARM64_CRC)
if (crc32c_runtime_check()) {
has_fast_crc = true;
arch = "Arm64";
@@ -1227,7 +1229,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<Slow_CRC32>;
-#elif defined(__linux__) && defined(HAVE_ARM64_CRC)
+#elif defined(HAVE_ARM64_CRC)
if(crc32c_runtime_check()) {
pmull_runtime_flag = crc32c_pmull_runtime_check();
return ExtendARMImpl;
diff --git a/util/crc32c_arm64.cc b/util/crc32c_arm64.cc
index 566810f4b..e26897499 100644
--- a/util/crc32c_arm64.cc
+++ b/util/crc32c_arm64.cc
@@ -5,9 +5,11 @@

#include "util/crc32c_arm64.h"

-#if defined(__linux__) && defined(HAVE_ARM64_CRC)
+#if defined(HAVE_ARM64_CRC)

+#if defined(__linux__)
#include <asm/hwcap.h>
+#endif
#ifdef ROCKSDB_AUXV_GETAUXVAL_PRESENT
#include <sys/auxv.h>
#endif
@@ -66,7 +68,7 @@ __attribute__((__no_sanitize_undefined__))
#endif
#endif
uint32_t crc32c_arm64(uint32_t crc, unsigned char const *data,
- unsigned len) {
+ size_t len) {
const uint8_t *buf8;
const uint64_t *buf64 = (uint64_t *)data;
int length = (int)len;
diff --git a/util/crc32c_arm64.h b/util/crc32c_arm64.h
index a12354683..168cc81c2 100644
--- a/util/crc32c_arm64.h
+++ b/util/crc32c_arm64.h
@@ -7,6 +7,7 @@
#define UTIL_CRC32C_ARM64_H

#include <cinttypes>
+#include <cstddef>

#if defined(__aarch64__) || defined(__AARCH64__)

@@ -33,7 +34,7 @@
PREF4X64L1(buffer, (PREF_OFFSET), 8) \
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 bool crc32c_pmull_runtime_check(void);

5 changes: 2 additions & 3 deletions libs/rocksdb/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ install_linux() {
}

install_macos(){
$sh_c "wget https://github.com/facebook/rocksdb/archive/refs/tags/${VERSION}.tar.gz"
$sh_c "tar -zxvf ${VERSION}.tar.gz"
$sh_c "mv rocksdb-${VERSION_NUM} rocksdb"
$sh_c "git clone https://github.com/facebook/rocksdb.git"
$sh_c "cd rocksdb && git checkout ${VERSION} && git apply --reject ../arm64_crc.patch"
$sh_c "cd rocksdb && make uninstall"
$sh_c "cd rocksdb && make shared_lib"
$sh_c "cd rocksdb && make install-shared"
Expand Down

0 comments on commit 233ad87

Please sign in to comment.