Skip to content

Commit

Permalink
Remove again all unsafe code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfbiedert committed Dec 14, 2024
1 parent 530b4d8 commit 22e766b
Showing 1 changed file with 1 addition and 45 deletions.
46 changes: 1 addition & 45 deletions src/svm/kernel/rbf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,53 +34,9 @@ fn compute_core(rbf: Rbf, vectors: &MatSimd<f32x8, Rows>, feature: &VecSimd<f32x
}
}

#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
#[target_feature(enable = "avx")]
#[inline]
unsafe fn compute_avx(rbf: Rbf, vectors: &MatSimd<f32x8, Rows>, feature: &VecSimd<f32x8>, output: &mut [f64]) {
compute_core(rbf, vectors, feature, output);
}

#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
#[target_feature(enable = "avx2")]
#[inline]
unsafe fn compute_avx2(rbf: Rbf, vectors: &MatSimd<f32x8, Rows>, feature: &VecSimd<f32x8>, output: &mut [f64]) {
compute_core(rbf, vectors, feature, output);
}

#[cfg(target_arch = "aarch64")]
#[target_feature(enable = "neon")]
#[inline]
unsafe fn compute_neon(rbf: Rbf, vectors: &MatSimd<f32x8, Rows>, feature: &VecSimd<f32x8>, output: &mut [f64]) {
compute_core(rbf, vectors, feature, output);
}

#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
#[inline]
fn compute(rbf: Rbf, vectors: &MatSimd<f32x8, Rows>, feature: &VecSimd<f32x8>, output: &mut [f64]) {
if is_x86_feature_detected!("avx2") {
unsafe { compute_avx2(rbf, vectors, feature, output) }
} else if is_x86_feature_detected!("avx") {
unsafe { compute_avx(rbf, vectors, feature, output) }
} else {
compute_core(rbf, vectors, feature, output);
}
}

#[cfg(target_arch = "aarch64")]
#[inline]
fn compute(rbf: Rbf, vectors: &MatSimd<f32x8, Rows>, feature: &VecSimd<f32x8>, output: &mut [f64]) {
if std::arch::is_aarch64_feature_detected!("neon") {
unsafe { compute_neon(rbf, vectors, feature, output) }
} else {
compute_core(rbf, vectors, feature, output)
}
}

#[cfg(not(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64")))]
#[inline]
fn compute(rbf: Rbf, vectors: &MatSimd<f32x8, Rows>, feature: &VecSimd<f32x8>, output: &mut [f64]) {
compute_core(rbf, vectors, feature, output)
compute_core(rbf, vectors, feature, output);
}

impl KernelDense for Rbf {
Expand Down

0 comments on commit 22e766b

Please sign in to comment.