Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions fearless_simd/examples/srgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,41 @@

use fearless_simd::{Level, dispatch, f32x4, prelude::*};

// This block shows how to use safe wrappers for compile-time enforcement
// of using valid SIMD intrinsics.
#[cfg(feature = "safe_wrappers")]
#[inline(always)]
fn copy_alpha<S: Simd>(a: f32x4<S>, b: f32x4<S>) -> f32x4<S> {
// #[cfg(target_arch = "x86_64")]
// if let Some(avx2) = a.simd.level().as_avx2() {
// return avx2
// .sse4_1
// ._mm_blend_ps::<8>(a.into(), b.into())
// .simd_into(a.simd);
// }
#[cfg(target_arch = "aarch64")]
if let Some(neon) = a.simd.level().as_neon() {
return neon
.neon
.vcopyq_laneq_f32::<3, 3>(a.into(), b.into())
.simd_into(a.simd);
#[cfg(target_arch = "aarch64")]
use core::arch::aarch64::{float32x4_t, vcopyq_laneq_f32};
#[cfg(target_arch = "x86")]
use core::arch::x86::{__m128, _mm_blend_ps};
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::{__m128, _mm_blend_ps};

#[cfg(target_arch = "aarch64")]
fearless_simd::neon_kernel! {
#[inline]
fn copy_alpha_neon(a: float32x4_t, b: float32x4_t) -> float32x4_t {
vcopyq_laneq_f32::<3, 3>(a, b)
}
}

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fearless_simd::sse4_2_kernel! {
#[inline]
fn copy_alpha_sse4_2(a: __m128, b: __m128) -> __m128 {
_mm_blend_ps::<8>(a, b)
}
let mut result = a;
result[3] = b[3];
result
}

// This block lets the example compile without safe wrappers.
#[cfg(not(feature = "safe_wrappers"))]
#[inline(always)]
fn copy_alpha<S: Simd>(a: f32x4<S>, b: f32x4<S>) -> f32x4<S> {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
if let Some(sse4_2) = a.simd.level().as_sse4_2() {
return copy_alpha_sse4_2(sse4_2, a.into(), b.into()).simd_into(a.simd);
}

#[cfg(target_arch = "aarch64")]
if let Some(_neon) = a.simd.level().as_neon() {
unsafe {
return core::arch::aarch64::vcopyq_laneq_f32::<3, 3>(a.into(), b.into())
.simd_into(a.simd);
}
if let Some(neon) = a.simd.level().as_neon() {
return copy_alpha_neon(neon, a.into(), b.into()).simd_into(a.simd);
}

let mut result = a;
result[3] = b[3];
result
Expand Down
1 change: 1 addition & 0 deletions fearless_simd/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod avx2;
mod fallback;
mod kernel_macros;
#[cfg(target_arch = "aarch64")]
mod neon;
mod ops;
Expand Down
Loading
Loading