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

Add asm clobbers for PPC / PPC64 #111335

Closed

Conversation

Richard-Rogalski
Copy link

Marking this as a draft as I have a few questions :D

For the VMX ones, I get error[E0599]: no variant or associated item named 'v19' found for enum 'PowerPCInlineAsmReg' in the current scope. I'm fairly new to rust, and can't quite figure out what's triggering this :). Also, should these be included, when they're not available on every power CPU?

The second thing is this compiles without errors when I make the code specify PowerPC, but not when I make it for PowerPC64: error[E0599]: no variant or associated item named 'PowerPC64' found for enum 'InlineAsmClobberAbi' in the current scope. Some arches (like riscv) appear to use the same for 32bit and 64bit, while others have different clobbers for each. I'm pretty sure the registers correct for both 32 & 64 bit, but will PPC64 use this?

The third thing is r11 and r12. They're both volatile but have 'special' uses.

r11       Volatile register used in calls by pointer and as an
          environment pointer for languages which require one
r12       Volatile register used for exception handling and glink code

I looked at other arches and their registers to see whether I should include these or not, but am unsure :).

@Amanieu

@rustbot
Copy link
Collaborator

rustbot commented May 8, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @wesleywiser (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@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 May 8, 2023
@@ -885,6 +886,10 @@ impl InlineAsmClobberAbi {
"C" | "system" | "efiapi" => Ok(InlineAsmClobberAbi::LoongArch),
_ => Err(&["C", "system", "efiapi"]),
},
InlineAsmArch::PowerPC => match name {
Copy link
Member

Choose a reason for hiding this comment

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

You need to add PowerPC64 here as well if both use the same calling convention. If the registers are different then you need a separate 32-bit and 64-bit InlineAsmClobberAbi.

@Amanieu
Copy link
Member

Amanieu commented May 8, 2023

For the VMX ones, I get error[E0599]: no variant or associated item named 'v19' found for enum 'PowerPCInlineAsmReg' in the current scope. I'm fairly new to rust, and can't quite figure out what's triggering this :). Also, should these be included, when they're not available on every power CPU?

You need to define the VMX registers in compiler/rustc_target/src/asm/powerpc.rs. You'll need to create a vreg class for them.

The second thing is this compiles without errors when I make the code specify PowerPC, but not when I make it for PowerPC64: error[E0599]: no variant or associated item named 'PowerPC64' found for enum 'InlineAsmClobberAbi' in the current scope. Some arches (like riscv) appear to use the same for 32bit and 64bit, while others have different clobbers for each. I'm pretty sure the registers correct for both 32 & 64 bit, but will PPC64 use this?

See code comments.

The third thing is r11 and r12. They're both volatile but have 'special' uses.

All volatile registers need to be included. The point of clobber_abi is that it should include all registers that may be modified by a function call. This also needs to include the condition code registers.

@rust-log-analyzer

This comment has been minimized.

@Richard-Rogalski
Copy link
Author

Sorry, forgot pushing updates the PR. Still not done yet :)

@@ -885,6 +886,10 @@ impl InlineAsmClobberAbi {
"C" | "system" | "efiapi" => Ok(InlineAsmClobberAbi::LoongArch),
_ => Err(&["C", "system", "efiapi"]),
},
InlineAsmArch::PowerPC | InlineAsmArch::PowerPC64 => match name {
"C" | "system" | "efiapi" => Ok(InlineAsmClobberAbi::PowerPC),
Copy link
Member

Choose a reason for hiding this comment

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

This should not include efiapi.

@@ -817,6 +818,12 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg) => cx.type_i32(),
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => cx.type_i32(),
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => cx.type_f64(),
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vreg) => {
cx.type_vector(cx.type_i64(), 2)
} //no clue if this is right :D
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 correct if the tests accept it! You'll need to extend the tests in tests/assembly/asm to include tests for vector regisers. Have a look at the AArch64/x86 tests for examples.

@@ -610,7 +610,8 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg) => "r",
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => "b",
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => "f",
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::cr)
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vreg) => "v",
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::cr)//should this not be either x or y ?
Copy link
Member

Choose a reason for hiding this comment

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

We are explicitly making these clobber-only for now. We can always revisit this later if needed.

@@ -47,6 +48,7 @@ impl PowerPCInlineAsmRegClass {
}
}
Self::freg => types! { _: F32, F64; },
Self::vreg => todo!(), //not quite sure :)
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be something like:

types! {
    vsx: I8, I16, I32, I64, F32, F64,
    altivec: VecI8(16), VecI16(8), VecI32(4), VecI64(2), VecF32(4), VecF64(2);
}

Altivec allows 128-bit vector types, and VSX allows using scalars in vector registers.

However this should be verified by writing asm tests that checks that LLVM is able to generate the correct code for these.

@Richard-Rogalski
Copy link
Author

Should I make these tests in tests/assembly, or tests/codegen? and should I make a new file for these, or what .rs file would be most appropriate for these kinds of tests?

@Amanieu
Copy link
Member

Amanieu commented May 13, 2023

The tests should be added to tests/assembly/asm/powerpc-types.rs. You need to test every supported input type with the vreg class, and with an explicit vN register.

@Dylan-DPC Dylan-DPC added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 12, 2023
@Dylan-DPC
Copy link
Member

@Richard-Rogalski any updates on this?

@Richard-Rogalski
Copy link
Author

bah, yeah, I should get back to this. I got a little lost, I'll try again when i get the time

@Dylan-DPC
Copy link
Member

Closing this as inactive. Feel free to reöpen this pr or create a new pr if you get the time to work on this. Thanks

@Dylan-DPC Dylan-DPC closed this Feb 9, 2024
@Dylan-DPC Dylan-DPC added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 9, 2024
@ky438
Copy link

ky438 commented May 26, 2024

@Richard-Rogalski - any chance you can get this over the line?

@Richard-Rogalski
Copy link
Author

I've gotten better at rust in the time since I started this PR. If i am recalling correctly, everything is done except for the tests :p I'll take another crack at this starting today @ky438 .

@ky438
Copy link

ky438 commented May 27, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. 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.

7 participants