Skip to content

aarch64: use intrinsics::simd for horizontal add and abs #1872

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

Merged
merged 2 commits into from
Jul 15, 2025

Conversation

folkertdev
Copy link
Contributor

No description provided.

@rustbot
Copy link
Collaborator

rustbot commented Jul 12, 2025

r? @Amanieu

rustbot has assigned @Amanieu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@folkertdev folkertdev changed the title Aarch64 horizontal add aarch64: use intrinsics::simd for horizontal add and abs 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)"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc llvm/llvm-project#148388

Just kept this as-is for now, but from what I can tell i64::wrapping_abs would be equivalent.

Copy link
Member

Choose a reason for hiding this comment

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

The LLVM issue is closed, is this comment still relevant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

@folkertdev folkertdev force-pushed the aarch64-horizontal-add branch from 66c1b0f to 06ff4f9 Compare July 14, 2025 23:36
@Amanieu Amanieu enabled auto-merge July 14, 2025 23:45
@Amanieu Amanieu added this pull request to the merge queue Jul 15, 2025
Merged via the queue into rust-lang:master with commit c6b2f48 Jul 15, 2025
62 checks passed
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.

3 participants