-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Create a sve_zeroinitializer compiler intrinsic
#157110
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
Open
CrooseGit
wants to merge
2
commits into
rust-lang:main
Choose a base branch
from
CrooseGit:dev/reucru01/sve_zeroinitializer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| //@ assembly-output: emit-asm | ||
| //@ needs-llvm-components: aarch64 | ||
| //@ compile-flags: --target aarch64-unknown-linux-gnu -C target-feature=+sve | ||
|
|
||
| #![allow(incomplete_features, internal_features)] | ||
| #![feature(simd_ffi, rustc_attrs, link_llvm_intrinsics, core_intrinsics)] | ||
| #![crate_type = "lib"] | ||
|
|
||
| #[rustc_scalable_vector(16)] | ||
| #[allow(non_camel_case_types)] | ||
| pub struct svbool_t(bool); | ||
|
|
||
| #[rustc_scalable_vector(8)] | ||
| #[allow(non_camel_case_types)] | ||
| pub struct svint16_t(i16); | ||
|
|
||
| #[rustc_scalable_vector(4)] | ||
| #[allow(non_camel_case_types)] | ||
| pub struct svfloat32_t(f32); | ||
|
|
||
| #[rustc_scalable_vector] | ||
| #[allow(non_camel_case_types)] | ||
| pub struct svfloat32x2_t(svfloat32_t, svfloat32_t); | ||
|
|
||
| #[target_feature(enable = "sve")] | ||
| fn svbool_zeroinitializer() -> svbool_t { | ||
| unsafe { std::intrinsics::simd::scalable::sve_zeroinitializer() } | ||
| } | ||
|
|
||
| #[target_feature(enable = "sve")] | ||
| pub fn svint16_zeroinitializer() -> svint16_t { | ||
| unsafe { std::intrinsics::simd::scalable::sve_zeroinitializer() } | ||
| } | ||
|
|
||
| #[target_feature(enable = "sve")] | ||
| pub fn svfloat32x2_zeroinitializer() -> svfloat32x2_t { | ||
| unsafe { std::intrinsics::simd::scalable::sve_zeroinitializer() } | ||
| } | ||
|
|
||
| // CHECK-LABEL: svbool_false | ||
| #[no_mangle] | ||
| #[target_feature(enable = "sve")] | ||
| pub unsafe extern "C" fn svbool_false() -> svbool_t { | ||
| // CHECK: pfalse p0.b | ||
| svbool_zeroinitializer() | ||
| } | ||
|
|
||
| // CHECK-LABEL: svint_zero | ||
| #[no_mangle] | ||
| #[target_feature(enable = "sve")] | ||
| pub unsafe extern "C" fn svint_zero() -> svint16_t { | ||
| // CHECK: movi v0.2d, #0000000000000000 | ||
| svint16_zeroinitializer() | ||
| } | ||
|
|
||
| // CHECK-LABEL: svfloat_tuple_zero | ||
| #[no_mangle] | ||
| #[target_feature(enable = "sve")] | ||
| pub unsafe extern "C" fn svfloat_tuple_zero() -> svfloat32x2_t { | ||
| // CHECK: movi v0.2d, #0000000000000000 | ||
| svfloat32x2_zeroinitializer() | ||
| } |
70 changes: 70 additions & 0 deletions
70
tests/codegen-llvm/scalable-vectors/zeroinitializer-intrinsic.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| //@ edition: 2021 | ||
| //@ only-aarch64 | ||
| #![crate_type = "lib"] | ||
| #![allow(incomplete_features, internal_features)] | ||
| #![feature(simd_ffi, rustc_attrs, link_llvm_intrinsics, core_intrinsics)] | ||
|
|
||
| #[rustc_scalable_vector(16)] | ||
| #[allow(non_camel_case_types)] | ||
| pub struct svbool_t(bool); | ||
|
|
||
| #[rustc_scalable_vector(8)] | ||
| #[allow(non_camel_case_types)] | ||
| pub struct svint16_t(i16); | ||
|
|
||
| #[rustc_scalable_vector(4)] | ||
| #[allow(non_camel_case_types)] | ||
| pub struct svfloat32_t(f32); | ||
|
|
||
| #[rustc_scalable_vector(2)] | ||
| #[allow(non_camel_case_types)] | ||
| pub struct svfloat64_t(f64); | ||
|
|
||
| #[rustc_scalable_vector] | ||
| #[allow(non_camel_case_types)] | ||
| pub struct svfloat32x2_t(svfloat32_t, svfloat32_t); | ||
|
|
||
| #[no_mangle] | ||
| #[target_feature(enable = "sve")] | ||
| // CHECK-LABEL: svbool_zeroinitializer | ||
| pub fn svbool_zeroinitializer() -> svbool_t { | ||
| // CHECK: start: | ||
| // CHECK: ret <vscale x 16 x i1> zeroinitializer | ||
| unsafe { std::intrinsics::simd::scalable::sve_zeroinitializer() } | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| #[target_feature(enable = "sve")] | ||
| // CHECK-LABEL: svint16_zeroinitializer | ||
| pub fn svint16_zeroinitializer() -> svint16_t { | ||
| // CHECK: start: | ||
| // CHECK: ret <vscale x 8 x i16> zeroinitializer | ||
| unsafe { std::intrinsics::simd::scalable::sve_zeroinitializer() } | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| #[target_feature(enable = "sve")] | ||
| // CHECK-LABEL: svfloat32_zeroinitializer | ||
| pub fn svfloat32_zeroinitializer() -> svfloat32_t { | ||
| // CHECK: start: | ||
| // CHECK: ret <vscale x 4 x float> zeroinitializer | ||
| unsafe { std::intrinsics::simd::scalable::sve_zeroinitializer() } | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| #[target_feature(enable = "sve")] | ||
| // CHECK-LABEL: svfloat64_zeroinitializer | ||
| pub fn svfloat64_zeroinitializer() -> svfloat64_t { | ||
| // CHECK: start: | ||
| // CHECK: ret <vscale x 2 x double> zeroinitializer | ||
| unsafe { std::intrinsics::simd::scalable::sve_zeroinitializer() } | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| #[target_feature(enable = "sve")] | ||
| // CHECK-LABEL: svfloat32x2_zeroinitializer | ||
| pub fn svfloat32x2_zeroinitializer() -> svfloat32x2_t { | ||
| // CHECK: start: | ||
| // CHECK: ret { <vscale x 4 x float>, <vscale x 4 x float> } zeroinitializer | ||
| unsafe { std::intrinsics::simd::scalable::sve_zeroinitializer() } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Is this equivalent to
mem::zeroed()?View changes since the review
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.
I don't believe it works the same way.
I chose to use
zeroinitializerbecause this is how thesvpfalseintrinsic generates apfalsein clang and I am trying to replicate this.Uh oh!
There was an error while loading. Please reload this page.
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.
Yeah, but Rust isn't specified by LLVM IR. The exact LLVM intrinsic used here is an implementation detail. It can sometimes be worth mentioning for informational purposes, but an LLVM IR operation can never be the definition of any part of the Rust language.
So, if this is not the same as
mem::zeroed, then how is it different?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.
mem::zeroed()requires a Sized type, scalable vectors are not Sized. Well, the compiler currently pretends they're Sized so they can be Copy, but that's a temporary hack and leaning on it too hard will probably ICE or emit wrong LLVM IR.Uh oh!
There was an error while loading. Please reload this page.
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.
I see, makes sense. The docs should then say something like
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.
But modulo the Sized mess and uncertain ontology of scalable vectors, this should indeed be equivalent to
men::zeroed(). It returns a scalable vector with all bytes set to zero, but the number of bytes isn’t a compile time constant.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.
At the intrinsic level we do not need to distinguish
zeroedfromsve_zeroinitializer.I think we could just relax the Sized bound on the intrinsic and let the backends figure it out based on the layout