Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loongarch64 support #72

Open
wants to merge 1 commit into
base: FRocksDB-6.20.3
Choose a base branch
from
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: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64|AARCH64")
endif(HAS_ARMV8_CRC)
endif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64|AARCH64")

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)
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,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 arm64 aarch64 sparc64, $(MACHINE)))
ifneq (,$(filter amd64 ppc64 ppc64le arm64 aarch64 sparc64 loongarch64, $(MACHINE)))
ARCH := 64
else
ARCH := 32
Expand All @@ -1972,7 +1972,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
Expand Down
2 changes: 2 additions & 0 deletions build_tools/build_detect_platform
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ if test "0$PORTABLE" -eq 0; then
COMMON_FLAGS="$COMMON_FLAGS -mcpu=$POWER -mtune=$POWER "
elif test -n "`echo $TARGET_ARCHITECTURE | grep ^s390x`"; then
COMMON_FLAGS="$COMMON_FLAGS -march=z10 "
elif test -n "`echo $TARGET_ARCHITECTURE | grep ^loongarch64`"; then
COMMON_FLAGS="$COMMON_FLAGS -march=loongarch64 "
elif test -n "`echo $TARGET_ARCHITECTURE | grep -e^arm -e^aarch64`"; then
# TODO: Handle this with approprite options.
COMMON_FLAGS="$COMMON_FLAGS"
Expand Down
6 changes: 5 additions & 1 deletion java/src/main/java/org/rocksdb/util/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public static boolean isAarch64() {
return ARCH.contains("aarch64");
}

public static boolean isLoongArch64() {
return ARCH.contains("loongarch64");
}

public static boolean isPowerPC() {
return ARCH.contains("ppc");
}
Expand Down Expand Up @@ -103,7 +107,7 @@ private static String getLibcPostfix() {
public static String getJniLibraryName(final String name) {
if (isUnix()) {
final String arch = is64Bit() ? "64" : "32";
if (isPowerPC() || isAarch64()) {
if (isPowerPC() || isAarch64() || isLoongArch64()) {
return String.format("%sjni-linux-%s%s", name, ARCH, getLibcPostfix());
} else if (isS390x()) {
return String.format("%sjni-linux%s", name, ARCH);
Expand Down
2 changes: 2 additions & 0 deletions port/port_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ static inline void AsmVolatilePause() {
asm volatile("yield");
#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
}
Expand Down
6 changes: 6 additions & 0 deletions third-party/folly/folly/Portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
#define FOLLY_AARCH64 0
#endif

#if defined(__loongarch64)
#define FOLLY_LOONGARCH64 1
#else
#define FOLLY_LOONGARCH64 0
#endif

#if defined(__powerpc64__)
#define FOLLY_PPC64 1
#else
Expand Down
2 changes: 2 additions & 0 deletions third-party/folly/folly/portability/Asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ inline void asm_volatile_pause() {
asm volatile("yield");
#elif FOLLY_PPC64
asm volatile("or 27,27,27");
#elif defined(__loongarch64)
asm volatile("dbar 0");
#endif
}
} // namespace folly
1 change: 1 addition & 0 deletions util/xxhash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ typedef XXH64_hash_t xxh_u64;
|| defined(_M_ARM64) || defined(__aarch64__) || defined(__arm64__) /* aarch64 */ \
|| defined(__PPC64__) || defined(__PPC64LE__) || defined(__ppc64__) || defined(__powerpc64__) /* ppc64 */ \
|| defined(__mips64__) || defined(__mips64)) /* mips64 */ \
|| defined(__loongarch64) /* loongarch64 */ \
|| (!defined(SIZE_MAX) || SIZE_MAX < ULLONG_MAX) /* check limits */
# define XXH_REROLL_XXH64 1
# else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ static inline tokutime_t toku_time_now(void) {
return result;
#elif defined(__powerpc__)
return __ppc_get_timebase();
#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
Expand Down