未验证 提交 6ea9991d 编写于 作者: W Wu Xiaotian 提交者: GitHub

add support for loongarch64 (#851)

上级 047868e3
......@@ -119,6 +119,9 @@ elseif(${ARCHITECTURE} STREQUAL "aarch64")
set(MARCH_CFLAGS "-march=armv8-a+crc" )
set(MTUNE_CFLAGS "-mtune=generic" )
set(ARCH_LDFLAGS "-latomic")
elseif(${ARCHITECTURE} STREQUAL "loongarch64")
set(MARCH_CFLAGS "-march=la464" )
set(MTUNE_CFLAGS "-mabi=lp64d" )
else()
message(FATAL_ERROR "UNSUPPORT BUILD ARCH: ${ARCHITECTURE}")
endif()
......@@ -95,8 +95,8 @@ static __inline__ void easy_spin_lock(easy_atomic_t* lock)
__asm__(".byte 0xf3, 0x90");
#elif defined(__aarch64__)
__asm__("yield"); // for ARM
#elif defined(__sw_64__)
//sw currently not provide related opcode
#elif defined(__sw_64__) || defined(__loongarch64)
// These platforms currently do not natively support such operation
#else
#error arch unsupported
#endif
......@@ -158,6 +158,8 @@ static __inline__ int easy_spinrwlock_rdlock(easy_spinrwlock_t* lock)
asm("pause");
#elif defined(__aarch64__)
asm("yield"); // for ARM
#elif defined(__sw_64__) || defined(__loongarch64)
// These platforms currently do not natively support such operation
#else
#error arch unsupported
#endif
......@@ -199,6 +201,8 @@ static __inline__ int easy_spinrwlock_wrlock(easy_spinrwlock_t* lock)
asm("pause");
#elif defined(__aarch64__)
asm("yield"); // for ARM
#elif defined(__sw_64__) || defined(__loongarch64)
// These platforms currently do not natively support such operation
#else
#error arch unsupported
#endif
......
......@@ -531,7 +531,7 @@ EV_CPP(extern "C" {
#define ev_mb() __asm__ __volatile ("mfence" ::: "memory")
#elif defined(__aarch64__)
#define ev_mb() __asm__ __volatile ("dsb sy" ::: "memory") //for ARM
#elif defined(__sw_64__)
#elif defined(__sw_64__) || defined(__loongarch64)
#define ev_mb() __sync_synchronize()
#else
#error arch unsupported
......
......@@ -139,7 +139,7 @@ static __inline__ uint64_t rdtscp()
__asm__ __volatile__("rdtscp" : "=a"(rax), "=d"(rdx)::"%rcx");
return (rdx << 32) + rax;
}
#elif defined(__sw_64__)
#elif defined(__sw_64__) || defined(__loongarch64)
static __inline__ uint64_t rdtsc()
{
return (uint64_t)easy_time_now();
......@@ -163,7 +163,7 @@ static __inline__ uint64_t rdtsc()
#endif
#if defined(__x86_64__) || defined(__sw_64__)
#if defined(__x86_64__) || defined(__sw_64__) || defined(__loongarch64)
uint64_t get_cpufreq_khz()
{
char line[256];
......
......@@ -26,6 +26,9 @@ ob_lib_add_target(oblib_lib_coro_context
coro/context/asm/make_sw_64_sysv_elf_gas.S
coro/context/asm/jump_sw_64_sysv_elf_gas.S
coro/context/asm/ontop_sw_64_aapcs_elf_gas.S
coro/context/asm/jump_loongarch64_sysv_elf_gas.S
coro/context/asm/make_loongarch64_sysv_elf_gas.S
coro/context/asm/ontop_loongarch64_sysv_elf_gas.S
)
disable_pch(oblib_lib_coro_context)
......
......@@ -711,6 +711,8 @@ struct signalfd_siginfo
#define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("")
#elif defined __ia64__
#define ECB_MEMORY_FENCE __asm__ __volatile__ ("mf" : : : "memory")
#elif defined __loongarch__
#define ECB_MEMORY_FENCE __asm__ __volatile__ ("dbar 0" : : : "memory")
#elif defined __m68k__
#define ECB_MEMORY_FENCE __asm__ __volatile__ ("" : : : "memory")
#elif defined __m88k__
......
......@@ -85,7 +85,7 @@ inline void load128(__uint128_t& target, types::uint128_t* source)
__ATOMIC_SEQ_CST)
#define LOAD128(dest, src) __atomic_load(((types::uint128_t*)(src)), ((types::uint128_t*)(&(dest))), __ATOMIC_SEQ_CST)
#elif defined(__sw_64__)
#elif defined(__sw_64__) || defined(__loongarch64)
inline bool cas128(volatile types::uint128_t* target, types::uint128_t* cmp, types::uint128_t with)
{
int ret = 0;
......
......@@ -36,7 +36,7 @@ namespace common {
OB_ATOMIC_EVENT(atomic_pause); \
asm("yield\n"); \
}) // for ARM
#elif defined(__sw_64__)
#elif defined(__sw_64__) || defined(__loongarch64)
#define WEAK_BARRIER() __sync_synchronize()
#define PAUSE()
#else
......
......@@ -422,6 +422,9 @@ for RHEL4 support (GCC 3 doesn't support this instruction) */
#define crc32_sse42_byte \
crc = __crc32cb(crc, (uint8_t)*buf); \
len--, buf++
#elif defined(__loongarch64)
#define crc32_sse42_byte nullptr
#define crc32_sse42_quadword nullptr
#elif defined(__sw_64__)
#define crc32_sse42_byte nullptr
......@@ -2849,7 +2852,7 @@ uint64_t crc64_sse42_dispatch(uint64_t crc, const char* buf, int64_t len)
ob_crc64_sse42_func = &fast_crc64_sse42_manually;
_OB_LOG(INFO, "Use manual crc32 table lookup for crc64 calculate");
#endif
#elif defined(__sw_64__)
#elif defined(__sw_64__) || defined(__loongarch64)
ob_crc64_sse42_func = &fast_crc64_sse42_manually;
_OB_LOG(INFO, "Use manual crc32 table lookup for crc64 calculate");
#else
......
......@@ -73,7 +73,7 @@ OB_INLINE int64_t co_current_time()
return now;
}
#if defined(__x86_64__)
#if defined(__loongarch64) || defined(__sw_64__) || defined(__x86_64__)
OB_INLINE uint64_t co_rdtscp(void)
{
return co_current_time() * 1000;
......@@ -86,11 +86,6 @@ OB_INLINE uint64_t co_rdtscp(void)
asm volatile("mrs %0, cntvct_el0" : "=r"(virtual_timer_value));
return virtual_timer_value;
}
#elif defined(__sw_64__)
OB_INLINE uint64_t co_rdtscp(void)
{
return co_current_time() * 1000;
}
#else
#error arch unsupported
#endif
......
/*******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 8 | 16 | 24 | *
* ------------------------------------------------- *
* | FS0 | FS1 | FS2 | FS3 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 40 | 48 | 56 | *
* ------------------------------------------------- *
* | FS4 | FS5 | FS6 | FS7 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 72 | 80 | 88 | *
* ------------------------------------------------- *
* | S0 | S1 | S2 | S3 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | S4 | S5 | S6 | S7 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | S8 | FP | RA | PC | *
* ------------------------------------------------- *
* *
* *****************************************************/
.file "jump_loongarch64_sysv_elf_gas.S"
.text
.globl jump_fcontext
.align 2
.type jump_fcontext,@function
jump_fcontext:
# reserve space on stack
addi.d $sp, $sp, -160
# save fs0 - fs7
fst.d $fs0, $sp, 0
fst.d $fs1, $sp, 8
fst.d $fs2, $sp, 16
fst.d $fs3, $sp, 24
fst.d $fs4, $sp, 32
fst.d $fs5, $sp, 40
fst.d $fs6, $sp, 48
fst.d $fs7, $sp, 56
# save s0 - s8, fp, ra
st.d $s0, $sp, 64
st.d $s1, $sp, 72
st.d $s2, $sp, 80
st.d $s3, $sp, 88
st.d $s4, $sp, 96
st.d $s5, $sp, 104
st.d $s6, $sp, 112
st.d $s7, $sp, 120
st.d $s8, $sp, 128
st.d $fp, $sp, 136
st.d $ra, $sp, 144
# save RA as PC
st.d $ra, $sp, 152
# store SP (pointing to context-data) in A2
move $a2, $sp
# restore SP (pointing to context-data) from A0
move $sp, $a0
# load fs0 - fs7
fld.d $fs0, $sp, 0
fld.d $fs1, $sp, 8
fld.d $fs2, $sp, 16
fld.d $fs3, $sp, 24
fld.d $fs4, $sp, 32
fld.d $fs5, $sp, 40
fld.d $fs6, $sp, 48
fld.d $fs7, $sp, 56
#load s0 - s8, fp, ra
ld.d $s0, $sp, 64
ld.d $s1, $sp, 72
ld.d $s2, $sp, 80
ld.d $s3, $sp, 88
ld.d $s4, $sp, 96
ld.d $s5, $sp, 104
ld.d $s6, $sp, 112
ld.d $s7, $sp, 120
ld.d $s8, $sp, 128
ld.d $fp, $sp, 136
ld.d $ra, $sp, 144
# return transfer_t from jump
# pass transfer_t as first arg in context function
# a0 == FCTX, a1 == DATA
move $a0, $a2
# load PC
ld.d $a2, $sp, 152
# restore stack
addi.d $sp, $sp, 160
# jump to context
jr $a2
.size jump_fcontext, .-jump_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits
/*******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 8 | 16 | 24 | *
* ------------------------------------------------- *
* | FS0 | FS1 | FS2 | FS3 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 40 | 48 | 56 | *
* ------------------------------------------------- *
* | FS4 | FS5 | FS6 | FS7 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 72 | 80 | 88 | *
* ------------------------------------------------- *
* | S0 | S1 | S2 | S3 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | S4 | S5 | S6 | S7 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | S8 | FP | RA | PC | *
* ------------------------------------------------- *
* *
* *****************************************************/
.file "make_loongarch64_sysv_elf_gas.S"
.text
.globl make_fcontext
.align 2
.type make_fcontext,@function
make_fcontext:
# shift address in A0 to lower 16 byte boundary
bstrins.d $a0, $zero, 3, 0
# reserve space for context-data on context-stack
addi.d $a0, $a0, -160
# third arg of make_fcontext() == address of context-function
st.d $a2, $a0, 152
# save address of finish as return-address for context-function
# will be entered after context-function returns
la.local $a4, finish
st.d $a4, $a0, 144
# return pointer to context-data
jr $ra
finish:
# exit code is zero
li.d $a0, 0
# call _exit(0)
b %plt(_exit)
.size make_fcontext, .-make_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits
/*******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 8 | 16 | 24 | *
* ------------------------------------------------- *
* | FS0 | FS1 | FS2 | FS3 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 40 | 48 | 56 | *
* ------------------------------------------------- *
* | FS4 | FS5 | FS6 | FS7 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 72 | 80 | 88 | *
* ------------------------------------------------- *
* | S0 | S1 | S2 | S3 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | S4 | S5 | S6 | S7 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | S8 | FP | RA | PC | *
* ------------------------------------------------- *
* *
* *****************************************************/
.file "ontop_loongarch64_sysv_elf_gas.S"
.text
.globl ontop_fcontext
.align 2
.type ontop_fcontext,@function
ontop_fcontext:
# reserve space on stack
addi.d $sp, $sp, -160
# save fs0 - fs7
fst.d $fs0, $sp, 0
fst.d $fs1, $sp, 8
fst.d $fs2, $sp, 16
fst.d $fs3, $sp, 24
fst.d $fs4, $sp, 32
fst.d $fs5, $sp, 40
fst.d $fs6, $sp, 48
fst.d $fs7, $sp, 56
# save s0 - s8, fp, ra
st.d $s0, $sp, 64
st.d $s1, $sp, 72
st.d $s2, $sp, 80
st.d $s3, $sp, 88
st.d $s4, $sp, 96
st.d $s5, $sp, 104
st.d $s6, $sp, 112
st.d $s7, $sp, 120
st.d $s8, $sp, 128
st.d $fp, $sp, 136
st.d $ra, $sp, 144
# save RA as PC
st.d $ra, $sp, 152
# store SP (pointing to context-data) in A3
move $a3, $sp
# restore SP (pointing to context-data) from A0
move $sp, $a0
# load fs0 - fs11
fld.d $fs0, $sp, 0
fld.d $fs1, $sp, 8
fld.d $fs2, $sp, 16
fld.d $fs3, $sp, 24
fld.d $fs4, $sp, 32
fld.d $fs5, $sp, 40
fld.d $fs6, $sp, 48
fld.d $fs7, $sp, 56
#load s0 - s11, fp, ra
ld.d $s0, $sp, 64
ld.d $s1, $sp, 72
ld.d $s2, $sp, 80
ld.d $s3, $sp, 88
ld.d $s4, $sp, 96
ld.d $s5, $sp, 104
ld.d $s6, $sp, 112
ld.d $s7, $sp, 120
ld.d $s8, $sp, 128
ld.d $fp, $sp, 136
ld.d $ra, $sp, 144
# return transfer_t from jump
# pass transfer_t as first arg in context function
# a0 == FCTX, a1 == DATA
move $a0, $a3
# adjust stack
addi.d $sp, $sp, 160
# jump to context
jr $a2
.size ontop_fcontext, .-ontop_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits
......@@ -104,7 +104,7 @@ union ObHeadNode {
#define FREELIST_VERSION(x) ((static_cast<intptr_t>((x).data_)) >> 48)
#define SET_FREELIST_POINTER_VERSION(x, p, v) \
(x).data_ = (((reinterpret_cast<intptr_t>(p)) & 0x0000FFFFFFFFFFFFULL) | (((v)&0xFFFFULL) << 48))
#elif defined(__sw_64__)
#elif defined(__sw_64__) || defined(__loongarch64)
#define FREELIST_POINTER(x) \
(reinterpret_cast<void*>((((static_cast<intptr_t>((x).data_)) << 16) >> 16) | \
(((~(((static_cast<intptr_t>((x).data_)) << 16 >> 63) - 1)) >> 48) << 48))) // sign extend
......
......@@ -444,6 +444,8 @@ inline bool is_cpu_support_sse42()
return 0 != (data & CPUID_STD_SSE4_2);
#elif defined(__aarch64__)
return 0;
#elif defined(__loongarch64)
return 0;
#elif defined(__sw_64__)
return 0;
#else
......
......@@ -384,7 +384,7 @@ private:
typedef common::RWLock::RLockGuard RLockGuard;
typedef common::RWLock::WLockGuard WLockGuard;
mutable common::RWLock lock_;
#elif defined(__sw_64__)
#elif defined(__sw_64__) || defined(__loongarch64)
typedef common::SpinRLockGuard RLockGuard;
typedef common::SpinWLockGuard WLockGuard;
mutable common::SpinRWLock lock_;
......
......@@ -307,7 +307,7 @@ private:
typedef common::RWLock::RLockGuard RLockGuard;
typedef common::RWLock::WLockGuard WLockGuard;
mutable common::RWLock lock_;
#elif defined(__sw_64__)
#elif defined(__sw_64__) || defined(__loongarch64)
typedef common::RWLock::RLockGuard RLockGuard;
typedef common::RWLock::WLockGuard WLockGuard;
mutable common::RWLock lock_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册