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 2 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
35 changes: 35 additions & 0 deletions arch/arch-loongarch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#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.

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


#if __loongarch_xlen == 64
Copy link
Member

Choose a reason for hiding this comment

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

确认下新工具链是看这个?手册上叫GRLEN的东西到代码里就叫xlen?最早我拿到的正式公开源码是没这个的我记得

Copy link
Collaborator Author

@cnmushiba cnmushiba Aug 16, 2021

Choose a reason for hiding this comment

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

https://github.com/loongson/glibc/pull/10/files ,公布出来的又给删了。。。,我有句话不知当不当讲,算了不讲了

Copy link
Member

@xen0n xen0n Aug 16, 2021

Choose a reason for hiding this comment

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

我去。。。这帮人才,RV 叫 xlen 的东西,不想借鉴(降低别人学习成本)也就算了,自己手册上写了个 GRLEN,然后现在既不给用 xlen 也不给用 grlen,让人用 __WORDSIZE???

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

按道理gcc应该内置这个宏的。。。,现在是啥都没了。。。,我很难过

Choose a reason for hiding this comment

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

https://github.com/loongson/glibc/pull/10/files ,公布出来的又给删了。。。,我有句话不知当不当讲,算了不讲了

为啥要删了呢? 直接去问问 ^^

Copy link
Member

Choose a reason for hiding this comment

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

我觉得不妨先加着,工具链那边感觉干活不讲一致性,而且朝令夕改。不能就着他们的代码行为,下游也凑合,应该基于这边的具体使用场景给他们改进做事方式的压力。

Copy link

Choose a reason for hiding this comment

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

https://github.com/loongson/glibc/pull/10/files ,公布出来的又给删了。。。,我有句话不知当不当讲,算了不讲了

是我删的,C库那个文件只是用来定义WORDSIZE的。

如果要定义类似 xlen 的宏,应该在gcc中定义,具体请参考riscv:

https://github.com/loongson/glibc/blob/c8793900942229e22e54624c17fa5c9ce5bc6576/sysdeps/riscv/bits/wordsize.h#L20
https://github.com/loongson/gcc/blob/ac1026d11b3a7bc40609b0177c390b37964037af/gcc/config/riscv/riscv-c.c#L57-L59

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

https://github.com/loongson/glibc/pull/10/files ,公布出来的又给删了。。。,我有句话不知当不当讲,算了不讲了

为啥要删了呢? 直接去问问 ^^

那个加错地方了,应该加在gcc的内置宏里的

Copy link
Member

Choose a reason for hiding this comment

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

@yetist 新的预定义符号预期叫啥?谁来改?

Copy link

Choose a reason for hiding this comment

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

建议在gcc那边讨论一下

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

__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

#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