Skip to content

Commit d5ee7ec

Browse files
committed
add loongarch64 support
1 parent 833952f commit d5ee7ec

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

CMake/Options.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
OPTION(ENABLE_COVERAGE "enable code coverage" OFF)
22
OPTION(ENABLE_DEBUG "enable debug build" OFF)
33
OPTION(ENABLE_SSE "enable SSE4.2 buildin function" ON)
4+
OPTION(ENABLE_LSX "enable Loongson LSX buildin function" OFF)
45
OPTION(ENABLE_FRAME_POINTER "enable frame pointer on 64bit system with flag -fno-omit-frame-pointer, on 32bit system, it is always enabled" ON)
56
OPTION(ENABLE_LIBCPP "using libc++ instead of libstdc++, only valid for clang compiler" OFF)
67
OPTION(ENABLE_BOOST "using boost instead of native compiler c++0x support" OFF)
@@ -32,7 +33,11 @@ ENDIF(ENABLE_FRAME_POINTER STREQUAL ON)
3233

3334
IF(ENABLE_SSE STREQUAL ON)
3435
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
35-
ENDIF(ENABLE_SSE STREQUAL ON)
36+
ENDIF(ENABLE_SSE STREQUAL ON)
37+
38+
IF(ENABLE_LSX STREQUAL ON)
39+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mlsx")
40+
ENDIF(ENABLE_LSX STREQUAL ON)
3641

3742
IF(NOT TEST_HDFS_PREFIX)
3843
SET(TEST_HDFS_PREFIX "./" CACHE STRING "default directory prefix used for test." FORCE)

bootstrap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,17 @@ if [[ ! -x ${cmake} ]]; then
111111
die "cannot found cmake"
112112
fi
113113

114+
if [[ `arch` = loongarch64 ]];then
115+
enable_sse="OFF"
116+
enable_lsx="ON"
117+
fi
118+
114119
# Configure
115120
${cmake} -DENABLE_DEBUG=${enable_build} -DCMAKE_INSTALL_PREFIX=${prefix_dirs} \
116121
-DCMAKE_C_COMPILER=${c_compiler} -DCMAKE_CXX_COMPILER=${cxx_compiler} \
117122
-DCMAKE_PREFIX_PATH=${dependency_dir} -DENABLE_BOOST=${enable_boost} \
118123
-DENABLE_COVERAGE=${enable_coverage} -DENABLE_LIBCPP=${enable_clang_lib} ${source_dir} \
124+
-DENABLE_SSE=${enable_sse} -DENABLE_LSX=${enable_lsx} \
119125
|| die "failed to configure the project"
120126

121127
echo 'bootstrap success. Run "make" to build.'

src/common/HWCrc32c.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,51 @@
3434
#include <cpuid.h>
3535
#endif
3636

37-
#if ((defined(__X86__) || defined(__i386__) || defined(i386) || defined(_M_IX86) || defined(__386__) || defined(__x86_64__) || defined(_M_X64)))
37+
#if defined(__loongarch64)
38+
#include <larchintrin.h>
39+
#endif
40+
41+
#if ((defined(__X86__) || defined(__i386__) || defined(i386) || defined(_M_IX86) || defined(__386__) || defined(__x86_64__) || defined(_M_X64) || defined(__loongarch64)))
3842
#if !defined(__SSE4_2__)
3943

4044
namespace Hdfs {
4145
namespace Internal {
4246

4347
#if defined(__LP64__)
4448
static inline uint64_t _mm_crc32_u64(uint64_t crc, uint64_t value) {
49+
#if defined(__loongarch64)
50+
crc = __crcc_w_d_w(value,crc);
51+
#else
4552
asm("crc32q %[value], %[crc]\n" : [crc] "+r"(crc) : [value] "rm"(value));
53+
#endif
4654
return crc;
4755
}
4856
#endif
4957

5058
static inline uint32_t _mm_crc32_u16(uint32_t crc, uint16_t value) {
59+
#if defined(__loongarch64)
60+
crc = __crcc_w_h_w(value,crc);
61+
#else
5162
asm("crc32w %[value], %[crc]\n" : [crc] "+r"(crc) : [value] "rm"(value));
63+
#endif
5264
return crc;
5365
}
5466

5567
static inline uint32_t _mm_crc32_u32(uint32_t crc, uint64_t value) {
68+
#if defined(__loongarch64)
69+
crc = __crcc_w_w_w(value,crc);
70+
#else
5671
asm("crc32l %[value], %[crc]\n" : [crc] "+r"(crc) : [value] "rm"(value));
72+
#endif
5773
return crc;
5874
}
5975

6076
static inline uint32_t _mm_crc32_u8(uint32_t crc, uint8_t value) {
77+
#if defined(__loongarch64)
78+
crc = __crcc_w_b_w(value,crc);
79+
#else
6180
asm("crc32b %[value], %[crc]\n" : [crc] "+r"(crc) : [value] "rm"(value));
81+
#endif
6282
return crc;
6383
}
6484

@@ -86,7 +106,7 @@ bool HWCrc32c::available() {
86106
*/
87107
__get_cpuid(1, &eax, &ebx, &ecx, &edx);
88108
return (ecx & (1 << 20)) != 0;
89-
#elif ((defined(__arm__) || defined(__aarch64__)))
109+
#elif ((defined(__arm__) || defined(__aarch64__) || defined(__loongarch64)))
90110
return true;
91111
#else
92112
return false;

0 commit comments

Comments
 (0)