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

arch: add loongarch support. #1

Open
wants to merge 3 commits into
base: la64/master
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
38 changes: 38 additions & 0 deletions arch/arch-loongarch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef ARCH_LOONGARCH_H
#define ARCH_LOONGARCH_H

#define FIO_ARCH (arch_loongarch)

#define read_barrier() __asm__ __volatile__("dbar 0": : :"memory")
#define write_barrier() __asm__ __volatile__("dbar 0": : :"memory")
#define nop __asm__ __volatile__("nop")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看别的好多架构好像都直接写的 do {} while (0) 你觉得如何?看下代码里实际都怎么使用这边定义的宏的,尽量不要无脑移植

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我感觉不好,这得看具体应用语境,这几个宏的调用本身就很简单,并不复杂。


static inline int arch_ffz(unsigned long bitmask)
{
unsigned long count;
if (~bitmask == 0) /* ffz() in lib/ffz.h does this. */
#if __loongarch_xlen == 64
return 63;
#define CTZ "ctz.d"
#define CTO "cto.d"
#else
return 31;
#define CTZ "ctz.w"
#define CTO "cto.w"
#endif

__asm__ __volatile__ (CTZ " %0, %1\n\t"
"bnez %0, 0f\n\t"
CTO " %0, %1\n\t"
"b 1f\n\t"
"0: move %0, $zero\n\t"
"1:\n\t"
:"=&r"(count)
:"r"(bitmask));

return count;
}

#define ARCH_HAVE_FFZ

#endif
3 changes: 3 additions & 0 deletions arch/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum {
arch_hppa,
arch_mips,
arch_aarch64,
arch_loongarch,

arch_generic,

Expand Down Expand Up @@ -77,6 +78,8 @@ extern unsigned long arch_flags;
#include "arch-hppa.h"
#elif defined(__aarch64__)
#include "arch-aarch64.h"
#elif defined(__loongarch__)
#include "arch-loongarch.h"
#else
#warning "Unknown architecture, attempting to use generic model."
#include "arch-generic.h"
Expand Down
4 changes: 2 additions & 2 deletions os/os-linux-syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@
#define __NR_sys_vmsplice 294
#endif

/* Linux syscalls for aarch64 */
#elif defined(ARCH_AARCH64_H)
/* Linux syscalls for aarch64 and loongarch */
#elif defined(ARCH_AARCH64_H) || defined(ARCH_LOONGARCH_H)
#ifndef __NR_ioprio_set
#define __NR_ioprio_set 30
#define __NR_ioprio_get 31
Expand Down