简体   繁体   English

RISC-V 中哪些寄存器被保存,哪些不被保存

[英]Which Registers are Saved and Not Saved in RISC-V

I'm taking a computer architecture course and am a bit lost on a few topics in the course.我正在上计算机体系结构课程,并且在课程中的一些主题上有点迷失。 Which registers are saved and not saved across a procedure call?在过程调用中保存和不保存哪些寄存器? What does this mean?这是什么意思?

On the list of registers, my book says that x8-x9 and x18-27 are saved registers.在寄存器列表上,我的书上说 x8-x9 和 x18-27 是保存的寄存器。 Does this mean that all others are not saved?这是否意味着所有其他人都没有得救? I've read a bit about callee and caller - does it have anything to do with this?我读过一些关于被叫方和来电方的内容——这与这有什么关系吗? I've read through the book and tried googling and cannot find a straight-forward answer, so I came here.我通读了这本书并尝试谷歌搜索但找不到直接的答案,所以我来到这里。 I'm taking this class just because there is not another option offered and do not have all of the prerequisites and background studies for it.我选择这个 class 只是因为没有提供其他选项并且没有所有先决条件和背景研究。 I'm struggling to keep up as a result, so please explain simply.结果我很难跟上,所以请简单地解释一下。

What is implemented right now in riscv-gcc:现在在 riscv-gcc 中实现了什么:
Call saved GPR: X8-X9 x18-x27调用保存的 GPR:X8-X9 x18-x27
Call saved FPR (if floating point is enabled): F8-F9 F18-F27调用保存的 FPR(如果启用浮点):F8-F9 F18-F27
All the other registers are fixed or Call clobbered.所有其他寄存器都是固定的或 Call 被破坏。

#define REG_ALLOC_ORDER                         \
{ \
  /* Call-clobbered GPRs.  */                       \
  15, 14, 13, 12, 11, 10, 16, 17, 6, 28, 29, 30, 31, 5, 7, 1,       \
  /* Call-saved GPRs.  */                       \
  8, 9, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,                 \
  /* GPRs that can never be exposed to the register allocator.  */  \
  0, 2, 3, 4,                               \
  /* Call-clobbered FPRs.  */                       \
  47, 46, 45, 44, 43, 42, 32, 33, 34, 35, 36, 37, 38, 39, 48, 49,   \
  60, 61, 62, 63,                           \
  /* Call-saved FPRs.  */                       \
  40, 41, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,           \
  /* None of the remaining classes have defined call-saved      \
     registers.  */                         \
  64, 65                                \
}  

ra is handled by the caller an d if you want you can take a look at riscv.c, you will see when ra is saved by riscv_save_reg_p . ra由调用者处理,如果需要,您可以查看 riscv.c,您将看到ra何时被riscv_save_reg_p保存。

For the LLVM Porting: The Callee saved GPR are: X1, X3-X4, X8-X9 and X18-X27 The Callee saved FPR (if floating point is enabled): F8-F9 F18-F27对于 LLVM 移植:被调用者保存的 GPR 是:X1、X3-X4、X8-X9 和 X18-X27 被调用者保存的 FPR(如果启用浮点):F8-F9 F18-F27

def CSR_ILP32_LP64
    : CalleeSavedRegs<(add X1, X3, X4, X8, X9, (sequence "X%u", 18, 27))>;

def CSR_ILP32F_LP64F
    : CalleeSavedRegs<(add CSR_ILP32_LP64,
                       F8_F, F9_F, (sequence "F%u_F", 18, 27))>;

def CSR_ILP32D_LP64D
    : CalleeSavedRegs<(add CSR_ILP32_LP64,
                       F8_D, F9_D, (sequence "F%u_D", 18, 27))>;

which is a little bit different from what gcc do.这与 gcc 所做的有点不同。 In gcc X3 and X4 are considered fixed.在 gcc 中,X3 和 X4 被认为是固定的。

For X2 in LLVM it is handled by setStackPointerRegisterToSaveRestore.对于 LLVM 中的 X2,它由 setStackPointerRegisterToSaveRestore 处理。

To try to explain in a simple way.尝试用通俗易懂的方式解释。 If a function uses a callee register (x8 for example) it will save it and restore it, which means that afterwards we will have the same value.如果 function 使用被调用者寄存器(例如 x8),它将保存并恢复它,这意味着之后我们将拥有相同的值。 if it uses a register which is not part of this list (ra for example with gcc), it will not do this job and it is up to the caller function to manage to restore the value before using it.如果它使用不属于此列表的寄存器(例如 gcc 的 ra),它将不会执行此工作,并且由调用者 function 在使用它之前设法恢复值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM