-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred in compiler/rustc_codegen_gcc |
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" | ||
} |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hmm, but when I set needs-llvm-components, I got:
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 |
46b0ebc
to
84fdac1
Compare
14f6234
to
3d19a90
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
☔ 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. | |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
This implements asm_experimental_arch (tracking issue #93335) for SPARC and SPARC64.
This PR includes:
r[0-31]
(reg
register class, LLVM/GCC constraintr
)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)icc
,xcc
) and floating-point condition codes (fcc*
)The following are not included:
g[0-7]
,o[0-7]
): GCC'sh
constraint (it seems that there is no corresponding constraint in LLVM?)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.
Refs:
(32-bit ISA) The SPARC Architecture Manual, Version 8
(64-bit ABI) System V Application Binary Interface SPARC Version 9 Processor Supplement, Rev 1.35
(32-bit ABI) System V Application Binary Interface SPARC Processor Supplement, Third Edition
The above docs can be downloaded from https://sparc.org/technical-documents
https://temlib.org/pub/SparcStation/Standards/V8plus.pdf
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