Skip to content

PowerPC: Add intrinsics support vec_add(vector_double, vector_double)#2161

Open
lei137 wants to merge 3 commits into
rust-lang:mainfrom
lei137:addPPCVecAddInstrisics
Open

PowerPC: Add intrinsics support vec_add(vector_double, vector_double)#2161
lei137 wants to merge 3 commits into
rust-lang:mainfrom
lei137:addPPCVecAddInstrisics

Conversation

@lei137

@lei137 lei137 commented Jun 15, 2026

Copy link
Copy Markdown

Add intrinsics support on Linux on Power for vec_add(vector_double, vector_double).

AI Assissted.

@rustbot

rustbot commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @sayantn (or someone else) some time within the next two weeks.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @Amanieu, @adamgemmell, @davidtwco, @folkertdev, @sayantn
  • @Amanieu, @adamgemmell, @davidtwco, @folkertdev, @sayantn expanded to Amanieu, adamgemmell, davidtwco, folkertdev, sayantn
  • Random selection from Amanieu, adamgemmell, davidtwco, folkertdev, sayantn

@lei137

lei137 commented Jun 16, 2026

Copy link
Copy Markdown
Author

This is my first rust patch and is the first of a series of vsx intrinsics support patches.
Feedback on how the stdarch community like these type of implementation patches to be done is greatly appreciated.

Comment on lines +187 to 196
// Implement AltiVec's VectorAdd trait for vector_double to enable vec_add support
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
impl crate::core_arch::powerpc::altivec::sealed::VectorAdd<vector_double> for vector_double {
type Result = vector_double;
#[inline]
#[target_feature(enable = "vsx")]
unsafe fn vec_add(self, other: vector_double) -> Self::Result {
sealed::vec_add_double_double(self, other)
}
}

@folkertdev folkertdev Jun 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So is the argument here that if you got your hands on a vector_double then vsx must be enabled?

Because normally adding stricter target features on a trait method is error-prone: there is now an additional safety requirement on that trait method, which is that if that particular instance is called, the target feature must be enabled.

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes that was the idea. On PPC, vec_add(vector_double, vector_double) should result in code gen xvadddp, which is only available if vsx feature is enabled.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm yeah the s390x implementation has the same sort of problem with float in their case. Many instructions for f32 were only added in a later target feature. Actually this is fine for vec_add because the implementation is just simd_add, which will generate xvadddp when the right target features are available, or some fallback thing (using scalars, probably) when that target feature is not available.

type Result = vector_double;
#[inline]
#[target_feature(enable = "vsx")]
unsafe fn vec_add(self, other: vector_double) -> Self::Result {

@folkertdev folkertdev Jun 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this the only function you'd want to do this for? I'd guess not?

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sorry, I do not understand what you mean. Can you please elaborate?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

well what about vec_sub and other vec_* methods? Should they not also follow this pattern, or is vec_add special somehow?

@lei137 lei137 requested a review from folkertdev June 17, 2026 15:02
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.

4 participants