]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
support loongarch64 for rocksdb (#10036)
authorWenlong Zhang <zhangwenlong@loongson.cn>
Fri, 13 Jan 2023 16:42:44 +0000 (08:42 -0800)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Fri, 13 Jan 2023 16:42:44 +0000 (08:42 -0800)
Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/10036

Reviewed By: hx235

Differential Revision: D42424074

Pulled By: ajkr

fbshipit-source-id: 004adb75005a26bd01c5d568d1ec6ac442cd59dd

CMakeLists.txt
Makefile
port/port_posix.h
util/xxhash.h
utilities/transactions/lock/range/range_tree/lib/portability/toku_time.h

index 7a0000ac4ca53868faea34b29a18bfc3cbd87012..aaabfe1f7fe586dd961b30d26ec167d1f9dff004 100644 (file)
@@ -245,6 +245,14 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "s390x")
   endif(HAS_S390X_MARCH_NATIVE)
 endif(CMAKE_SYSTEM_PROCESSOR MATCHES "s390x")
 
+if(CMAKE_SYSTEM_PROCESSOR MATCHES "loongarch64")
+  CHECK_C_COMPILER_FLAG("-march=loongarch64" HAS_LOONGARCH64)
+  if(HAS_LOONGARCH64)
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=loongarch64 -mtune=loongarch64")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=loongarch64 -mtune=loongarch64")
+  endif(HAS_LOONGARCH64)
+endif(CMAKE_SYSTEM_PROCESSOR MATCHES "loongarch64")
+
 option(PORTABLE "build a portable binary" OFF)
 option(FORCE_SSE42 "force building with SSE4.2, even when PORTABLE=ON" OFF)
 option(FORCE_AVX "force building with AVX, even when PORTABLE=ON" OFF)
@@ -275,6 +283,9 @@ if(PORTABLE)
     if(CMAKE_SYSTEM_PROCESSOR MATCHES "^s390x")
       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=z196")
     endif()
+    if(CMAKE_SYSTEM_PROCESSOR MATCHES "^loongarch64")
+      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=loongarch64")
+    endif()
   endif()
 else()
   if(MSVC)
index 407de572d3274fedc017e520ccc2d73bc8420529..32d1fcd6b2ead709d6142f02a76f214550529ef2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2070,7 +2070,7 @@ JAVA_INCLUDE = -I$(JAVA_HOME)/include/ -I$(JAVA_HOME)/include/linux
 ifeq ($(PLATFORM), OS_SOLARIS)
        ARCH := $(shell isainfo -b)
 else ifeq ($(PLATFORM), OS_OPENBSD)
-       ifneq (,$(filter amd64 ppc64 ppc64le s390x arm64 aarch64 sparc64, $(MACHINE)))
+       ifneq (,$(filter amd64 ppc64 ppc64le s390x arm64 aarch64 sparc64 loongarch64, $(MACHINE)))
                ARCH := 64
        else
                ARCH := 32
@@ -2091,7 +2091,7 @@ ifneq ($(origin JNI_LIBC), undefined)
 endif
 
 ifeq (,$(ROCKSDBJNILIB))
-ifneq (,$(filter ppc% s390x arm64 aarch64 sparc64, $(MACHINE)))
+ifneq (,$(filter ppc% s390x arm64 aarch64 sparc64 loongarch64, $(MACHINE)))
        ROCKSDBJNILIB = librocksdbjni-linux-$(MACHINE)$(JNI_LIBC_POSTFIX).so
 else
        ROCKSDBJNILIB = librocksdbjni-linux$(ARCH)$(JNI_LIBC_POSTFIX).so
index ec6aa281d7a6e8cf1a93194df98e6ea27c8ae343..417fbf4f6114d3288e22961f7ed2934beb0a5675 100644 (file)
@@ -169,6 +169,8 @@ static inline void AsmVolatilePause() {
   asm volatile("isb");
 #elif defined(__powerpc64__)
   asm volatile("or 27,27,27");
+#elif defined(__loongarch64)
+  asm volatile("dbar 0");
 #endif
   // it's okay for other platforms to be no-ops
 }
index 195f06b39a5708cbec1dc656f6fe67afaa09a759..fa483b7ebecb4091582c8f1142eb13696d93a830 100644 (file)
@@ -1287,7 +1287,8 @@ XXH_PUBLIC_API XXH128_hash_t XXH128(const void* data, size_t len, XXH64_hash_t s
 
 #ifndef XXH_FORCE_ALIGN_CHECK  /* can be defined externally */
 #  if defined(__i386)  || defined(__x86_64__) || defined(__aarch64__) \
-   || defined(_M_IX86) || defined(_M_X64)     || defined(_M_ARM64) /* visual */
+   || defined(_M_IX86) || defined(_M_X64)     || defined(_M_ARM64) \
+   || defined(__loongarch64) /* visual */
 #    define XXH_FORCE_ALIGN_CHECK 0
 #  else
 #    define XXH_FORCE_ALIGN_CHECK 1
index 46111e7f0ff75155833eb105a37a8de30ecbcc6d..9b83c53511c864303b6b1f192c7ca14bcfdcc03c 100644 (file)
@@ -154,6 +154,10 @@ static inline tokutime_t toku_time_now(void) {
   uint64_t cycles;
   asm volatile("rdcycle %0" : "=r"(cycles));
   return cycles;
+#elif defined(__loongarch64)
+  unsigned long result;
+  asm volatile ("rdtime.d\t%0,$r0" : "=r" (result));
+  return result;
 #else
 #error No timer implementation for this platform
 #endif