aarch64: use intrinsics::simd for horizontal add and abs#1872
Merged
Amanieu merged 2 commits intorust-lang:masterfrom Jul 15, 2025
Merged
aarch64: use intrinsics::simd for horizontal add and abs#1872Amanieu merged 2 commits intorust-lang:masterfrom
aarch64: use intrinsics::simd for horizontal add and abs#1872Amanieu merged 2 commits intorust-lang:masterfrom
Conversation
Collaborator
aarch64: use intrinsics::simd for horizontal add and abs
folkertdev
commented
Jul 12, 2025
Comment on lines
-301
to
+308
| unsafe extern "unadjusted" { | ||
| #[cfg_attr( | ||
| any(target_arch = "aarch64", target_arch = "arm64ec"), | ||
| link_name = "llvm.aarch64.neon.abs.v1i64" | ||
| )] | ||
| fn _vabs_s64(a: int64x1_t) -> int64x1_t; | ||
| unsafe { | ||
| let neg: int64x1_t = simd_neg(a); | ||
| let mask: int64x1_t = simd_ge(a, neg); | ||
| simd_select(mask, a, neg) | ||
| } | ||
| unsafe { _vabs_s64(a) } | ||
| } | ||
| #[doc = "Absolute Value (wrapping)."] | ||
| #[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vabsd_s64)"] | ||
| #[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vabsq_s64)"] |
Contributor
Author
There was a problem hiding this comment.
the diff here is wonky because the order of the definitions changed.
Comment on lines
+13037
to
+13044
| # FIXME(llvm): this should be `i64::wrapping_abs` but it optimizes differently. | ||
| # See https://github.com/llvm/llvm-project/issues/148388. | ||
| - LLVMLink: | ||
| name: "vabsd_s64" | ||
| links: | ||
| - link: "llvm.aarch64.neon.abs.i64" | ||
| arch: aarch64,arm64ec |
Contributor
Author
There was a problem hiding this comment.
Just kept this as-is for now, but from what I can tell i64::wrapping_abs would be equivalent.
Member
There was a problem hiding this comment.
The LLVM issue is closed, is this comment still relevant?
Contributor
Author
There was a problem hiding this comment.
I updated the comment. it's kind of subtle, but the intrinsic keeps the value in a simd register, while the scalar version uses GPRs.
66c1b0f to
06ff4f9
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.