Skip to content

Commit

Permalink
stabilize aarch64 simd
Browse files Browse the repository at this point in the history
  • Loading branch information
Nugine committed Nov 15, 2022
1 parent cd1cfb0 commit 5a00b30
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 84 deletions.
14 changes: 7 additions & 7 deletions crates/uuid-simd/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use vsimd::{SIMD128, SIMD256};

#[cfg(any(
any(target_arch = "x86", target_arch = "x86_64"),
all(feature = "unstable", any(target_arch = "arm", target_arch = "aarch64")),
any(all(feature = "unstable", target_arch = "arm"), target_arch = "aarch64"),
target_arch = "wasm32"
))]
vsimd::item_group! {
Expand All @@ -14,7 +14,7 @@ vsimd::item_group! {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
use vsimd::isa::{AVX2, SSE2, SSE41};

#[cfg(all(feature = "unstable", any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(any(all(feature = "unstable", target_arch = "arm"), target_arch = "aarch64"))]
use vsimd::isa::NEON;

#[cfg(target_arch = "wasm32")]
Expand All @@ -29,7 +29,7 @@ use core::arch::x86_64::*;
#[cfg(all(feature = "unstable", target_arch = "arm"))]
use core::arch::arm::*;

#[cfg(all(feature = "unstable", target_arch = "aarch64"))]
#[cfg(target_arch = "aarch64")]
use core::arch::aarch64::*;

#[cfg(target_arch = "wasm32")]
Expand All @@ -47,7 +47,7 @@ pub fn i16x16_set_lane7<S: SIMD256>(s: S, a: V256, x: i16) -> V256 {
let a0 = unsafe { t(_mm_insert_epi16::<7>(t(a.0), x as i32)) };
return V256::from_v128x2((a0, a.1));
}
#[cfg(all(feature = "unstable", any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(any(all(feature = "unstable", target_arch = "arm"), target_arch = "aarch64"))]
if is_subtype!(S, NEON) {
return unsafe {
let a: uint8x16x2_t = t(a);
Expand Down Expand Up @@ -79,7 +79,7 @@ pub fn i32x8_set_lane7<S: SIMD256>(s: S, a: V256, x: i32) -> V256 {
let a1 = unsafe { t(_mm_insert_epi32::<3>(t(a.1), x)) };
return V256::from_v128x2((a.0, a1));
}
#[cfg(all(feature = "unstable", any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(any(all(feature = "unstable", target_arch = "arm"), target_arch = "aarch64"))]
if is_subtype!(S, NEON) {
return unsafe {
let a: uint8x16x2_t = t(a);
Expand All @@ -105,7 +105,7 @@ pub fn i32x4_get_lane3<S: SIMD128>(s: S, a: V128) -> i32 {
if is_subtype!(S, SSE41) {
return unsafe { _mm_extract_epi32::<3>(t(a)) };
}
#[cfg(all(feature = "unstable", any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(any(all(feature = "unstable", target_arch = "arm"), target_arch = "aarch64"))]
if is_subtype!(S, NEON) {
return unsafe { vgetq_lane_s32::<3>(t(a)) };
}
Expand All @@ -125,7 +125,7 @@ pub fn i16x8_get_lane7<S: SIMD128>(s: S, a: V128) -> i16 {
if is_subtype!(S, SSE2) {
return unsafe { _mm_extract_epi16::<7>(t(a)) as i16 };
}
#[cfg(all(feature = "unstable", any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(any(all(feature = "unstable", target_arch = "arm"), target_arch = "aarch64"))]
if is_subtype!(S, NEON) {
return unsafe { vgetq_lane_s16::<7>(t(a)) };
}
Expand Down
12 changes: 8 additions & 4 deletions crates/vsimd/src/isa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,22 @@ unsafe impl InstructionSet for NEON {

#[inline(always)]
fn is_enabled() -> bool {
#[cfg(feature = "unstable")]
#[cfg(target_arch = "arm")]
{
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
#[cfg(feature = "unstable")]
{
is_feature_detected!("neon")
}
#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(not(feature = "unstable"))]
{
false
}
}
#[cfg(not(feature = "unstable"))]
#[cfg(target_arch = "aarch64")]
{
is_feature_detected!("neon")
}
#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
{
false
}
Expand Down
11 changes: 5 additions & 6 deletions crates/vsimd/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,9 @@ macro_rules! dispatch {
};

(@resolve_static, "neon", $($arg_name: ident),*) => {
#[cfg(all(
feature = "unstable",
any(target_arch = "arm", target_arch = "aarch64"),
target_feature = "neon",
#[cfg(any(
all(feature = "unstable", target_arch = "arm", target_feature = "neon"),
all(target_arch = "aarch64", target_feature = "neon"),
))]
{
return unsafe { neon($($arg_name),*) }
Expand Down Expand Up @@ -278,7 +277,7 @@ macro_rules! dispatch {
};

(@resolve_dynamic, "neon") => {
#[cfg(all(feature = "unstable", any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(any(all(feature = "unstable", target_arch = "arm"), target_arch = "aarch64"))]
if $crate::isa::NEON::is_enabled() {
return neon;
}
Expand Down Expand Up @@ -393,7 +392,7 @@ macro_rules! dispatch {
simd = {$simd_fn:path},
target = {"neon"},
) => {
#[cfg(all(feature = "unstable", any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(any(all(feature = "unstable", target_arch = "arm"), target_arch = "aarch64"))]
#[inline]
#[target_feature(enable = "neon")]
$vis unsafe fn neon($($arg_name:$arg_type),*) -> $ret {
Expand Down
10 changes: 5 additions & 5 deletions crates/vsimd/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum Arch {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Sse2,

#[cfg(all(feature = "unstable", any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(any(all(feature = "unstable", target_arch = "arm"), target_arch = "aarch64"))]
Neon,

#[cfg(target_arch = "wasm32")]
Expand All @@ -39,7 +39,7 @@ impl Native {
return Self(Arch::Sse2);
}
}
#[cfg(all(feature = "unstable", any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(any(all(feature = "unstable", target_arch = "arm"), target_arch = "aarch64"))]
{
if is_feature_detected!("neon") {
return Self(Arch::Neon);
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Native {
Arch::Fallback => f(),
}
}
#[cfg(all(feature = "unstable", any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(any(all(feature = "unstable", target_arch = "arm"), target_arch = "aarch64"))]
{
match self.0 {
Arch::Neon => unsafe { arm::neon(f) },
Expand All @@ -84,7 +84,7 @@ impl Native {
}
#[cfg(not(any( //
any(target_arch = "x86", target_arch = "x86_64"), //
all(feature = "unstable", any(target_arch = "arm", target_arch = "aarch64")), //
any(all(feature = "unstable", target_arch = "arm"), target_arch = "aarch64"), //
target_arch = "wasm32" //
)))]
{
Expand Down Expand Up @@ -114,7 +114,7 @@ mod x86 {
generic_dispatch!(sse2, "sse2");
}

#[cfg(all(feature = "unstable", any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(any(all(feature = "unstable", target_arch = "arm"), target_arch = "aarch64"))]
mod arm {
generic_dispatch!(neon, "neon");
}
Expand Down
Loading

0 comments on commit 5a00b30

Please sign in to comment.