Skip to content

[compiler-rt][RISC-V] ILP32E/LP64E Save/Restore Grouping #95398

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

Merged
merged 1 commit into from
Jun 3, 2025
Merged
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
45 changes: 30 additions & 15 deletions compiler-rt/lib/builtins/riscv/restore.S
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
// them falling through into each other and don't want the linker to
// accidentally split them up, garbage collect, or reorder them.
//
// The entry points are grouped up into 2s for rv64 and 4s for rv32 since this
// is the minimum grouping which will maintain the required 16-byte stack
// alignment.
// For the conventional ABIs, entry points are grouped up into 2s for rv64 and
// 4s for rv32 since this is the minimum grouping which will maintain the
// required 16-byte stack alignment.
//
// For the ilp32e/lp64e abis, entry points are grouped into 1s, since this is
// the minimum grouping which will maintain the required 4-byte stack alignment.

.text

Expand Down Expand Up @@ -92,17 +95,23 @@ __riscv_restore_0:

.globl __riscv_restore_2
.type __riscv_restore_2,@function
__riscv_restore_2:
lw s1, 0(sp)
addi sp, sp, 4
// fallthrough into __riscv_restore_1/0

.globl __riscv_restore_1
.type __riscv_restore_1,@function
__riscv_restore_1:
lw s0, 0(sp)
addi sp, sp, 4
// fallthrough into __riscv_restore_0

.globl __riscv_restore_0
.type __riscv_restore_0,@function
__riscv_restore_2:
__riscv_restore_1:
__riscv_restore_0:
lw s1, 0(sp)
lw s0, 4(sp)
lw ra, 8(sp)
addi sp, sp, 12
lw ra, 0(sp)
addi sp, sp, 4
ret

#endif
Expand Down Expand Up @@ -188,17 +197,23 @@ __riscv_restore_0:

.globl __riscv_restore_2
.type __riscv_restore_2,@function
__riscv_restore_2:
ld s1, 0(sp)
addi sp, sp, 8
// fallthrough into __riscv_restore_1/0

.globl __riscv_restore_1
.type __riscv_restore_1,@function
__riscv_restore_1:
ld s0, 0(sp)
addi sp, sp, 8
// fallthrough into __riscv_restore_0

.globl __riscv_restore_0
.type __riscv_restore_0,@function
__riscv_restore_2:
__riscv_restore_1:
__riscv_restore_0:
ld s1, 0(sp)
ld s0, 8(sp)
ld ra, 16(sp)
addi sp, sp, 24
ld ra, 0(sp)
addi sp, sp, 8
ret

#endif
Expand Down
44 changes: 31 additions & 13 deletions compiler-rt/lib/builtins/riscv/save.S
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,28 @@ __riscv_save_0:

.globl __riscv_save_2
.type __riscv_save_2,@function
.globl __riscv_save_1
.type __riscv_save_1,@function
.globl __riscv_save_0
.type __riscv_save_0,@function
__riscv_save_2:
__riscv_save_1:
__riscv_save_0:
addi sp, sp, -12
sw s1, 0(sp)
sw s0, 4(sp)
sw ra, 8(sp)
jr t0

.globl __riscv_save_1
.type __riscv_save_1,@function
__riscv_save_1:
addi sp, sp, -8
sw s0, 0(sp)
sw ra, 4(sp)
jr t0

.globl __riscv_save_0
.type __riscv_save_0,@function
__riscv_save_0:
addi sp, sp, -4
sw ra, 0(sp)
jr t0

#endif

#elif __riscv_xlen == 64
Expand Down Expand Up @@ -208,18 +217,27 @@ __riscv_save_0:

.globl __riscv_save_2
.type __riscv_save_2,@function
__riscv_save_2:
addi sp, sp, -24
sw s1, 0(sp)
sw s0, 8(sp)
sw ra, 16(sp)
jr t0

.globl __riscv_save_1
.type __riscv_save_1,@function
__riscv_save_1:
addi sp, sp, -16
sw s0, 0(sp)
sw ra, 8(sp)
jr t0

.globl __riscv_save_0
.type __riscv_save_0,@function
__riscv_save_2:
__riscv_save_1:
__riscv_save_0:
addi sp, sp, -24
sd s1, 0(sp)
sd s0, 8(sp)
sd ra, 16(sp)
jr t0
addi sp, sp, -8
sw ra, 0(sp)
jr t0

#endif

Expand Down
Loading