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

Basic inline assembly support for SPARC and SPARC64 #132472

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

taiki-e
Copy link
Member

@taiki-e taiki-e commented Nov 1, 2024

This implements asm_experimental_arch (tracking issue #93335) for SPARC and SPARC64.

This PR includes:

  • General-purpose registers r[0-31] (reg register class, LLVM/GCC constraint r)
    Supported types: i8, i16, i32, i64 (SPARC64-only)
    Aliases: g[0-7] (r[0-7]), o[0-7] (r[8-15]), l[0-7] (r[16-23]), i[0-7] (r[24-31])
  • y register (clobber-only, needed for clobber_abi)
  • preserves_flags: Integer condition codes (icc, xcc) and floating-point condition codes (fcc*)

The following are not included:

  • 64-bit integer support on SPARC-V8+'s global or out registers (g[0-7], o[0-7]): GCC's h constraint (it seems that there is no corresponding constraint in LLVM?)
  • Floating-point registers (LLVM/GCC constraint e/f):
    I initially tried to implement this, but postponed it for now because there seemed to be several parts in LLVM that behaved differently than in the LangRef's description.
  • clobber_abi: Support for floating-point registers is needed.

Refs:

cc @thejpster (sparc-unknown-none-elf target maintainer)
(AFAIK, other sparc/sprac64 targets don't have target maintainers)

r? @Amanieu

@rustbot label +O-SPARC +A-inline-assembly

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 1, 2024
@rustbot
Copy link
Collaborator

rustbot commented Nov 1, 2024

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@rustbot rustbot added A-inline-assembly Area: Inline assembly (`asm!(…)`) O-SPARC Target: SPARC processors labels Nov 1, 2024
Comment on lines 55 to 59
pub(crate) fn is_v7_or_v8(arch: InlineAsmArch, target: &Target) -> bool {
// FIXME: There are any number of CPUs that imply SPARC-V8+, and checking the cpu
// string in the target specs is not the ideal approach here, but there
// doesn't seem to be another good way to do this yet (https://github.com/rust-lang/rust/pull/131222).
// However, in LLVM 20, feature "+v8plus" will be available for this:
// https://github.com/llvm/llvm-project/commit/aca971d336d9c7650120fc0fd6dfe58866408216
arch == InlineAsmArch::Sparc && target.options.cpu != "v9"
}
Copy link
Member Author

@taiki-e taiki-e Nov 1, 2024

Choose a reason for hiding this comment

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

cc #131222

UPDATE: latest version of this PR uses the target feature based approach #132472 (comment)

Copy link
Member Author

@taiki-e taiki-e Nov 2, 2024

Choose a reason for hiding this comment

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

Perhaps adding the v9 target feature and referencing it (and after LLVM 20, adding and referencing the v8plus target feature instead of v9.) would be a good idea?
https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/Sparc/Sparc.td#L35

Copy link
Member Author

Choose a reason for hiding this comment

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

Implemented the target feature based approach in 14f6234.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@taiki-e
Copy link
Member Author

taiki-e commented Nov 1, 2024

/checkout/tests/ui/asm/bad-arch.rs: revision [unspecified] should specify needs-llvm-components: as it has --target set

Hmm, but when I set needs-llvm-components, I got:

/checkout/tests/ui/asm/bad-arch.rs: revision [unspecified] specifies unknown LLVM component xtensa

IIUC, it seems difficult to retain this test since there is no builtin target other than xtensa that does not support inline assembly in rust-lang/rust after this PR, and xtensa can probably support inline assembly in LLVM 20 (llvm/llvm-project@dc2d0d5, inline assembly itself is already supported in esp-rs fork).

UPDATE: removed this test

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Nov 5, 2024

☔ The latest upstream changes (presumably #129884) made this pull request unmergeable. Please resolve the merge conflicts.

| SPARC | `r0`/`g0` | This is always zero and cannot be used as inputs or outputs. |
| SPARC | `r1`/`g1` | Used internally by LLVM. |
| SPARC | `r6`/`g6`, `r7`/`g7` | Reserved for system. |
| SPARC | `r31`/`i7` | Return address cannot be used as inputs or outputs. |
Copy link
Member

Choose a reason for hiding this comment

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

i6/o6 also need to be added to the list of stack/frame pointers.

Copy link
Member

Choose a reason for hiding this comment

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

And g5 needs to be mentioned as reserved on sparc32.

) -> &'static [(InlineAsmType, Option<Symbol>)] {
match self {
Self::reg => {
// FIXME: i64 is ok for g*/o* registers on SPARC-V8+ ("h" constraint in GCC)
Copy link
Member

Choose a reason for hiding this comment

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

This is better expressed as "v9": I64 in the macro. The feature name can later be changed to v8plus.

_target: &Target,
_is_clobber: bool,
) -> Result<(), &'static str> {
if is_v7_or_v8(arch, target_features) {
Copy link
Member

Choose a reason for hiding this comment

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

The condition used in LLVM is Subtarget.is64Bit(), not whether v8plus is supported. So this should check for InlineAsmArch::Sparc64 instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) O-SPARC Target: SPARC processors S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants