From 1cfe3528a224427310772bde698ba768cb5d9d05 Mon Sep 17 00:00:00 2001 From: Wenlong Zhang Date: Fri, 13 Jan 2023 08:42:44 -0800 Subject: [PATCH] support loongarch64 for rocksdb (#10036) 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 | 11 +++++++++++ Makefile | 4 ++-- port/port_posix.h | 2 ++ util/xxhash.h | 3 ++- .../lock/range/range_tree/lib/portability/toku_time.h | 4 ++++ 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a0000ac4..aaabfe1f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/Makefile b/Makefile index 407de572d..32d1fcd6b 100644 --- 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 diff --git a/port/port_posix.h b/port/port_posix.h index ec6aa281d..417fbf4f6 100644 --- a/port/port_posix.h +++ b/port/port_posix.h @@ -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 } diff --git a/util/xxhash.h b/util/xxhash.h index 195f06b39..fa483b7eb 100644 --- a/util/xxhash.h +++ b/util/xxhash.h @@ -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 diff --git a/utilities/transactions/lock/range/range_tree/lib/portability/toku_time.h b/utilities/transactions/lock/range/range_tree/lib/portability/toku_time.h index 46111e7f0..9b83c5351 100644 --- a/utilities/transactions/lock/range/range_tree/lib/portability/toku_time.h +++ b/utilities/transactions/lock/range/range_tree/lib/portability/toku_time.h @@ -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