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

Fix "call" pseudo instruction that uselessly modified register "t1" #104

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

pacalet
Copy link

@pacalet pacalet commented Dec 5, 2024

The assembler translates call label as a auipc / jalr pair:

auipc x6,imm1
jalr  x1,x6,imm2

It uses register x6 (t1) to do so while register x1 (ra) is available and must indeed be modified anyway to store the return address. Although the ILP32 Application Binary Interface (ABI) and other ABIs consider x6 as non-saved, I do not see any reason to enforce an ABI in RARS more than strictly needed. So, I suggest to translate call label as:

auipc x1,imm1
jalr  x1,x1,imm2

Note: one could claim that this is still ABI-related because we use x1 (ra). But using a register is unavoidable if one wants a call pseudo-instruction. Choosing x1 makes sense as it is the preferred register for this purpose in ILP32 and alike.

Note: another pseudo-instruction (and only one) also silently modifies a non-saved register: tail label. As its target register is x0 we cannot fix it as we did for call. My intuition is that tail shall be removed completely but this breaks backward compatibility. We should maybe add a warning in its brief description?

Copy link

github-actions bot commented Dec 5, 2024

Test Results

12 files  ±0  12 suites  ±0   37s ⏱️ +2s
 8 tests ±0   8 ✅ ±0  0 💤 ±0  0 ❌ ±0 
24 runs  ±0  24 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit cb37651. ± Comparison against base commit 11f9a9e.

@pacalet pacalet changed the title fix pseudo "call" instruction that uselessly modified register "t1" Fix pseudo "call" instruction that uselessly modified register "t1" Dec 5, 2024
@pacalet pacalet changed the title Fix pseudo "call" instruction that uselessly modified register "t1" Fix "call" pseudo instruction that uselessly modified register "t1" Dec 5, 2024
@privat
Copy link
Collaborator

privat commented Dec 18, 2024

What you propose is in fact conform to the standard and what GNU as does
https://github.com/riscv-non-isa/riscv-asm-manual/blob/39a23b69dded402bb41061deb1ae44efe99b80d1/src/asm-manual.adoc#L71

tail could keep using t1, but people, including students, that use tail should be advanced enough to understand the t1 surprise :)

@privat privat merged commit 1684491 into rarsm:master Dec 18, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants